Reputation: 470
The following code output 1, but why? The property is private and child class shouldn't have an access to it.
<?php
trait PropertiesTrait {
private $same = true;
}
class PropertiesExample {
use PropertiesTrait;
public function foo(){
echo $this->same;
}
}
(new PropertiesExample())->foo();
?>
Upvotes: 0
Views: 80
Reputation: 146430
You don't have child classes. You only have PropertiesExample
.
You are not accessing the property from outside. You have a getter method.
Upvotes: 3