Last time I wrote about Weirdest PHP construction I’ve ever seen, now I found another unusual PHP solution. PHP offers 3 visibility modifiers: private, protected and public. Private properties and methods can’t be accessed outside the object, as well as from inherited classes. With one exception… They can be accessed by other instances of the same class.

Last time I wrote about Weirdest PHP construction I’ve ever seen, now I found another unusual PHP solution. PHP offers 3 visibility modifiers: private, protected and public. Private properties and methods can’t be accessed outside the object, as well as from inherited classes. With one exception… They can be accessed by other instances of the same class. You can read more about it in the PHP manual

As you can see, Foo::modifyProperty altered the other object private property. In fact type-hinting isn’t required here, but lack of it may cause a lot of confusion 🙂
Although PHP offers such solutions I strongly recommend not using them in real life…

You can also read a translation of this post on http://xlab.pl You can read more about it in the PHP manual

As you can see, Foo::modifyProperty altered the other object private property. In fact type-hinting isn’t required here, but lack of it may cause a lot of confusion 🙂
Although PHP offers such solutions I strongly recommend not using them in real life…

You can also read a translation of this post on http://xlab.pl