part of the codes
in class file
class Address {
public $_house_number; //notice this one has underscore here
}
public function AddressDetails(){
$output ="<h1> House number </h1>";
$output .= $this->house_number; //notice no underscore here
echo $output;
}
in front page
<?php
include('address.class.inc');
$address = new Address();
$housenumber= $address->house_number=10; //notice no underscore in front, so value set to the no underscore version
$address->AddressDetails();
The question is how come I was able to set value to the property which I didn’t declare just under class declaration. In fact even if I don’t declare public $_house_number; at top it still works.