📄 readme
字号:
The purpose of this extension is to allow user-space overloading of objectproperty access and method calls. It has only one function, overload() whichtakes the name of the class that should have this functionality enabled. Butthe class has to define appropriate methods if it wants to have thisfunctionality: __get(), __set(), and __call(). So, overloading can beselective.Inside each handler the overloading is disabled so you can access objectproperties normally.Usage-----<?phpclass OO { var $a = 111; var $elem = array('b' => 9, 'c' => 42); function OO($aval = null) { $this->a = $aval; } function __get($prop_name, &$prop_value) { if (isset($this->elem[$prop_name])) { $prop_value = $this->elem[$prop_name]; return true; } else return false; } function __set($prop_name, $prop_value) { $this->elem[$prop_name] = $prop_value; return true; } function __call($method, $args, &$return_value) { print '-- OO::' . $method . "() was called.--\n"; $return_value = call_user_func_array(array(&$this, 'my_' . $method), $args); return true; } function my_whatever($f1, $f2, $f3) { var_dump($f1, $f2, $f3); return $f1 + $f2; } function __get_foo(&$prop_value) { $prop_value = 'Bam bam bam!'; return true; } function __set_count($prop_value) { if ($prop_value >= 1 && $prop_value <= 100) { $this->elem['COUNT'] = $prop_value; return true; } else return false; }}overload('OO');$o = new OO;print "\$o->a: $o->a\n";print "\$o->b: $o->b\n";print "\$o->c: $o->c\n";print "\$o->d: $o->d\n";$val = new stdclass;$val->prop = 555;$o->a = array($val);var_dump($o->a[0]->prop);var_dump($o->whatever(1, 2, 'a'));var_dump($o->foo);$o->count = 100;var_dump($o->COUNT);?>What doesn't work-----------------Invoking original overloading handlers, if the class had any.__set() only works to one level of property access, no chains yet.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -