|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2003-11-28 23:37 UTC] sniper@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 18:00:01 2025 UTC |
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 )