note 50119 added to language.oop5.overloading
| From: | thisisroot at gmail dot com | Date: | Fri, 18 Feb 2005 15:27:47 +0000 |
| Subject: | note 50119 added to language.oop5.overloading | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-85212@lists.php.net to get a copy of this message | ||
You can't mix offsetSet() of the ArrayAccess interface
(http://www.php.net/~helly/php/ext/spl/interfaceArrayAccess.html) and __get() in the same line.
Below, "FileManagerPrefs" is an object of class UserData which implements ArrayAccess.
There's a protected array of UserData objects in the User class, which are returned from
__get().
<?php
// This produces an error...
Application::getInstance()->user->FileManagerPrefs[ 'base'] =
'uploads/jack';
?>
Creates this error:
Fatal error: Cannot access undefined property for object with overloaded property access in __FILE__
on line __LINE__
However, __get() and offsetGet() play deceptively well together.
<?php
// This works fine!
echo Application::getInstance()->user->FileManager['base'];
?>
I guess it's a dereferencing issue with __get(). In my case, it makes more sense to have a
middle step (user->data['FileManager']['base']), but I wanted to tip off the
community before I move on.
----
Manual Page -- http://www.php.net/manual/en/language.oop5.overloading.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+50119
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50119&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50119&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50119&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50119&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50119&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+50119&report=yes
Search -- http://master.php.net/manage/user-notes.php