note 52453 added to language.oop5.overloading
| From: | Marius at osu1 dot php dot net | Date: | Mon, 02 May 2005 09:15:37 +0000 |
| Subject: | note 52453 added to language.oop5.overloading | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-88855@lists.php.net to get a copy of this message | ||
for anyone who's thinking about traversing some variable tree
by using __get() and __set(). i tried to do this and found one
problem: you can handle couple of __get() in a row by returning
an object which can handle consequential __get(), but you can't
handle __get() and __set() that way.
i.e. if you want to:
<?php
print($obj->val1->val2->val3); // three __get() calls
?> - this will work,
but if you want to:
<?php
$obj->val1->val2 = $val; // one __get() and one __set() call
?> - this will fail with message:
"Fatal error: Cannot access undefined property for object with
overloaded property access"
however if you don't mix __get() and __set() in one expression,
it will work:
<?php
$obj->val1 = $val; // only one __set() call
$val2 = $obj->val1->val2; // two __get() calls
$val2->val3 = $val; // one __set() call
?>
as you can see you can split __get() and __set() parts of
expression into two expressions to make it work.
by the way, this seems like a bug to me, will have to report it.
----
Manual Page -- http://www.php.net/manual/en/language.oop5.overloading.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+52453
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52453&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52453&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52453&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52453&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52453&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+52453&report=yes
Search -- http://master.php.net/manage/user-notes.php