#48523 [Opn->Fbk]: __call() is not invoked for private methods
ID: 48523
Updated by: felipe@php.net
Reported By: headden at karelia dot ru
-Status: Open
+Status: Feedback
Bug Type: Class/Object related
Operating System: FreeBSD 7.0
PHP Version: 5.2.9
New Comment:
Please try using this CVS snapshot:
http://snaps.php.net/php5.2-latest.tar.gz
For Windows:
http://windows.php.net/snapshots/
I can't reproduce it.
Previous Comments:
------------------------------------------------------------------------
[2009-06-10 18:05:56] headden at karelia dot ru
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 this bug report at http://bugs.php.net/?id=48523&edit=1
Thread (4 messages)