note 50119 deleted from language.oop5.overloading by cmb

From: Date: Sun, 18 Dec 2016 10:06:29 +0000
Subject: note 50119 deleted from language.oop5.overloading by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-208659@lists.php.net to get a copy of this message
Note Submitter: thisisroot at gmail dot com ---- 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.

« previous php.notes (#208659) next »