note 97163 added to class.arrayaccess
| From: | max at flashdroid dot com | Date: | Tue, 06 Apr 2010 01:49:40 +0000 |
| Subject: | note 97163 added to class.arrayaccess | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-167718@lists.php.net to get a copy of this message | ||
Objects implementing ArrayAccess may return objects by references in PHP 5.3.0.
You can implement your ArrayAccess object like this:
class Reflectable implements ArrayAccess {
public function set($name, $value) {
$this->{$name} = $value;
}
public function &get($name) {
return $this->{$name};
}
public function offsetGet($offset) {
return $this->get($offset);
}
public function offsetSet($offset, $value) {
$this->set($offset, $value);
}
...
}
This base class allows you to get / set your object properties using the [] operator just like in
Javascript:
class Boo extends Reflectable {
public $name;
}
$obj = new Boo();
$obj['name'] = "boo";
echo $obj['name']; // prints boo
----
Server IP: 66.207.199.35
Probable Submitter: 67.193.125.129
----
Manual Page -- http://www.php.net/manual/en/class.arrayaccess.php
Edit -- https://master.php.net/note/edit/97163
Del: integrated -- https://master.php.net/note/delete/97163/integrated
Del: useless -- https://master.php.net/note/delete/97163/useless
Del: bad code -- https://master.php.net/note/delete/97163/bad+code
Del: spam -- https://master.php.net/note/delete/97163/spam
Del: non-english -- https://master.php.net/note/delete/97163/non-english
Del: in docs -- https://master.php.net/note/delete/97163/in+docs
Del: other reasons-- https://master.php.net/note/delete/97163
Reject -- https://master.php.net/note/reject/97163
Search -- https://master.php.net/manage/user-notes.php