php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24735 call_user_func on parent method does not use parent private property
Submitted: 2003-07-21 07:50 UTC Modified: 2003-11-28 23:37 UTC
From: tater at potatoe dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 5CVS-2003-07-21 (dev) OS: OS X 10.2
Private report: No CVE-ID: None
 [2003-07-21 07:50 UTC] tater at potatoe dot com
Description:
------------
If I call a public function of a base class from a derived class directly, the base class's function can use private properties of the base class. If I call it via call_user_func() or call_user_func_array(), it acts like an overloaded function of the derived class, and doesn't see the private property (it ends up creating a dynamic property for the object).

One or the other of these is wrong. I'm hoping it's the second one.

Reproduce code:
---------------
<?php
class foo
{
    private $a;
    private $b;
    public function set_a($v) { $this->a = $v; }
    public function set_b($v) { $this->b = $v; }
}
class bar extends foo { }
$f = new foo;
$f->set_a(1);
call_user_func(array($f,'set_b'), 2);
$b = new bar;
$b->set_a(1);
call_user_func(array($b,'set_b'), 2);
print_r($f);
print_r($b);
?>

Expected result:
----------------
foo Object
(
    [a:private] => 1
    [b:private] => 2
)
bar Object
(
    [a:private] => 1
    [b:private] => 2
)

Actual result:
--------------
foo Object
(
    [a:private] => 1
    [b:private] => 2
)
bar Object
(
    [a:private] => 1
    [b:private] =>
    [b] => 2
)

Patches

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-11-28 23:37 UTC] sniper@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Aug 18 09:01:27 2024 UTC