From: headden at karelia dot ru Operating system: FreeBSD 7.0 PHP version: 5.2.9 PHP Bug Type: Class/Object related Bug description: __call() is not invoked for private methods
Description: ------------ I am using PHP 5.2.8, but I am not 100% sure this bug was removed from actual versions. The bug is that an attempt to access declared private method does not lead to __call() magic method invocation, but instead raises an error due to visibility as if there was no __call() declared at all. According to documentaion this should work the way it works for member variables - i.e. both undeclared and invisible methods should be resolved via __call(). In my version of PHP it works fine for variables (__get/__set work for both undeclared and invisible variables), but it does not work as intended for methods (__call works only for undeclared methods). Reproduce code: --------------- <?php class MyClass { private $v; private function f($a, $b, $c) { echo "f();"; } function __get($name) { echo "get($name)<br/>"; return $this->v; } function __set($name, $v) { echo "set($name)<br/>"; $this->v = $v; } function __call($name, $args) { echo "call($name, ".implode(", ", $args).")<br/>"; } } $o = new MyClass; $o->q = $o->q; // OK (undeclared variable) $o->v = $o->v; // OK (invisible variable) $o->g(1,2,3); // OK (undeclared method) $o->f(1,2,3); // FAILURE (invisible method) ?> Expected result: ---------------- get(q) set(q) get(v) set(v) call(g, 1, 2, 3) call(f, 1, 2, 3) Actual result: -------------- get(q) set(q) get(v) set(v) call(g, 1, 2, 3) Fatal error: Call to private method MyClass::f() from context '' in /.../test.php on line 15 -- Edit bug report at http://bugs.php.net/?id=48523&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=48523&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=48523&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=48523&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=48523&r=fixedcvs Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=48523&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=48523&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=48523&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=48523&r=needscript Try newer version: http://bugs.php.net/fix.php?id=48523&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=48523&r=support Expected behavior: http://bugs.php.net/fix.php?id=48523&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=48523&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=48523&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=48523&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=48523&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=48523&r=dst IIS Stability: http://bugs.php.net/fix.php?id=48523&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=48523&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=48523&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=48523&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=48523&r=mysqlcfg