News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Wojciech Sznapka's Blog:
Accessing private object property from other object in PHP
November 16, 2010 @ 12:25:53

Wojciech Sznapka has a new post to his blog showing an interesting OOP programming strick related to accessing private properties in one object from another if they're derived from 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.

In his code example he shows how to create two objects of the Foo class and, using getters and setters change the value of a private property from the first object on the second object.

0 comments voice your opinion now!
private property object exmaple object


blog comments powered by Disqus

Similar Posts

Chris Jones' Blog: Upgrading PHP Web Applications with Minimum Downtime using Oracle Editioning

Christoph Dorn's Blog: TIP: FirePHP data volume filtering

DevShed: Overloading and Object-Oriented Programming with PHP 5

Derick Rethans' Blog: Overloaded properties (__get)

DevShed: Working with Prepared Queries with PDO Objects in PHP 5


Community Events





Don't see your event here?
Let us know!


introduction unittest framework language testing configure release laravel list developer refactor interview install wordpress threedevsandamaybe code series community opinion podcast

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework