PHP OOP , discovered something that I don't understand why it's happening

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


$address = new Address();
$housenumber= $address->house_number=10; //notice no underscore in front, so value set to the no underscore version


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.

Yeah, this can be done in php. Even though it’s a bad practice to not declare instance variables before setting their value, it can be done.

Php allows you to declare and assign properties on the fly, although the visibility will always be public so you lose the power of encapsulation.

It’s not a bad practice in php. It’s a feature.

I found about it when I was watching overloading tutorial. Is that’s what this feature called?