News 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

PHPClasses.org: PHP Vulnerability May Halt Millions of Servers

Derick Rethans' Blog: Overloaded properties (__get)

Derick Rethans' Blog: Overloaded properties (__get)

Elizabeth Smith\'s Blog: String Class (Kal_String)

Matthew Weir O'Phinney's Blog: Overloading arrays in PHP 5.2.0


Community Events





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


composer opinion interview security release version podcast framework library series install community tool package introduction voicesoftheelephpant language symfony update laravel

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