Doing a var_dump on an object from either of the two classes gives the same result
Class Node{
public $parent = null;
public $right = null;
public $left = null;
function __construct($data){
$this->data = $data;
}
}
Class Node{
public $parent;
public $right;
public $left;
function __construct($data){
$this->data = $data;
}
}
For example
$a = new Node(2);
var_dump($a);
returns the following for either of the above classes
object(Node)#1 (4) {
["parent"]=>
NULL
["right"]=>
NULL
["left"]=>
NULL
["data"]=>
int(2)
}
This doesn't seem to be the case for variables.
$b;
var_dump($b);
If you intend for the property to have a value of null
is there a need to explicitly write that since php seems to do it automatically for you?
Also - According to this answer https://stackoverflow.com/a/6033090/784637, C++ gives undefined behavior if you try to get the value of an uninitialized variable. Does C++ automatically set the value of a property in a class to null
the way php does, if that property is uninitialized to a value?