News Feed
Sections




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

Tobias Schlitt's Blog:
Reflecting private properties
February 15, 2008 @ 12:02:00

Tobias Schlitt has posted a handy tip about using the Reflection API in PHP5 - specifically its accessing of private properties in a class.

I recently stumbled over reflecting private properties in PHP again. As you might know, this was not possible until now and if you tried this [code] PHP thanked it to you with this [error that is cannot access a non-public member].

He notes that, while the behaviour is correct, it still makes things like metaprogramming impossible. So, what's a developer to do? Patch it of course! Tobias and Derick Rethans persuaded two other developers (Derick and Marcus Borger) to include a patch that allows the Reflection API to see these private variables.

To make it work, you have to use the setAccessible method on the Reflection object to set which of the properties you want to be able to get at.

1 comment voice your opinion now!
reflection api setaccessible private properties


blog comments powered by Disqus

Similar Posts

Maarten Balliauw's Blog: Windows Azure SDK for PHP 4 released

ThinkingPHP: Google Analytics PHP API (CakePHP Model)

Zend Developer Zone: Using the Twitter API with PHP and PEAR

GoodPHPTutorials.com: Integrating the Authorize.Net AIM API with PHP

Hasin Hayder's Blog: Making a jobsite using PHP


Community Events

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


unittest threedevsandamaybe series extension laravel introduction laravel5 wordpress development community podcast language interview api framework voicesoftheelephpant opinion release feature library

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