note 108789 deleted from class.arrayobject by danbrown
| From: | danbrown@php.net | Date: | Thu, 24 May 2012 21:43:45 +0000 |
| Subject: | note 108789 deleted from class.arrayobject by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-188210@lists.php.net to get a copy of this message | ||
Note Submitter: maxim at inbox dot ru
----
Nice hack by php5 dot man at lightning dot hu
I was trying to extend it and found that if you delete substr condition, it gives you access to all
functions and callbacks ofc it is not so safe, but gives extra magic methods access for example:
class MyArrayObject extends ArrayObject
{
public function __call($func, $argv)
{
if (!is_callable($func) ) throw new
BadMethodCallException(__CLASS__.'->'.$func);
return call_user_func_array($func, array_merge(array($this->getArrayCopy()), $argv));
}
public function __set($key, $val)
{
return $this[$key]===false ? $this->offsetSet($key,$val) : $this[$key]=$val;
}
}
dunno what to add at __set when you can callbacking all over the functions.
ps also care about single argument passed to __call()