News Feed
Jobs Feed
Sections




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

Derick Rethans' Blog:
Overloaded properties (__get)
August 19, 2006 @ 15:29:56

Derick Rethans talks about something he noticed when working with backwards compatibility to PHP 5.1 for the eZ components project - the first of which is that __get doesn't behave itself in some situations.

The first issue is an extra notice in some cases. In our (ezcMailTools) class we implement a method that allows you to "reply" to a parsed e-mail message. you can see we loop over one of the seemingly public variables of the $mail class. However, the ezcMail class does not have this as a public member variable, but instead uses overload.

This all works 'fine' with PHP 5.1, however with PHP 5.2 the following notice was generated for this code:

Notice: Indirect modification of overloaded property ezcMail::$to has no effect in ../Mail/src/tools.php on line 364

The reason for this is that __get() only returns variables in read mode, while foreach() wants a variable in read/write mode as it tries to modify the internal array pointer. As it can't do this PHP 5.2 will now throw a warning on this.

The mentioned code examples are included and he includes the work-around that he found to help keep the issue from popping up again.

4 comments voice your opinion now!
get ez components overload property get ez components overload property


blog comments powered by Disqus

Similar Posts

The PHP Grind: Get real about PHP4 vs. PHP5!

Professional PHP Blog: The rumors of PEAR\'s demise are greatly exaggerated

Derick Rethans' Blog: Overloaded properties (__get)

Zend Developer Zone: Zend Framework 1.7.0 is now available

Sebastian Bergmann\'s BLog: Enterprise PHP {Components|Framework}


Community Events











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


package composer security application hack facebook framework podcast symfony2 opinion release unittest series install overview language introduction component hhvm code

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