php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48523 __call() is not invoked for private methods
Submitted: 2009-06-10 18:05 UTC Modified: 2009-06-10 19:24 UTC
From: headden at karelia dot ru Assigned:
Status: Closed Package: Class/Object related
PHP Version: 5.2.8 OS: FreeBSD 7.0
Private report: No CVE-ID: None
 [2009-06-10 18:05 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-06-10 18:19 UTC] felipe@php.net
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.
 [2009-06-10 18:36 UTC] headden at karelia dot ru
I can't reproduce it either with Win32 snapshot for 5.2.10RC2-dev. Looks like this bug was indeed removed between 5.2.8 and (5.2.9 or 5.2.10). The issue can be closed now, or for extreme clarity it can be tested against 5.2.9 snapshot as this version is still being bugtracked.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 23:01:28 2024 UTC