I have the property $value
which gives different error messages depending on whether I prepend private
to the variable declaration or not.
Class Node{
$value = NULL;
public function __construct($value){
$this->value = $value;
}
}
$node = new Node('hello');
echo $node->value;
PHP Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION in /home/ubuntu/new.php on line 4
However if I replace $value = NULL;
with private $value = NULL;
I get a different error message:
PHP Fatal error: Cannot access private property Node::$value in /home/ubuntu/new.php on line 11
I thought omitting the term private would automatically make the property private?
EDIT
I understand now that properties are public by default. How come I get an error when declaring the property $value
without the public
prepended to it?