Bug #48770 [Ver->Csd]: call_user_func_array() fails to call parent from inheriting class
| From: | pollita@php.net | Date: | Sun, 14 May 2017 16:40:42 +0000 |
| Subject: | Bug #48770 [Ver->Csd]: call_user_func_array() fails to call parent from inheriting class | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-209105@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=48770&edit=1
ID: 48770
Updated by: pollita@php.net
Reported by: lumeet at yahoo dot com
Summary: call_user_func_array() fails to call parent from
inheriting class
-Status: Verified
+Status: Closed
Type: Bug
Package: Scripting Engine problem
Operating System: *
PHP Version: 5.3, 6 (2009-08-01)
-Assigned To:
+Assigned To: pollita
Block user comment: N
Private report: N
New Comment:
Basically, what tyrael said.
Previous Comments:
------------------------------------------------------------------------
[2015-07-17 12:30:36] mbrodala at pagemachine dot de
I stumbled upon a similar error while trying to use a trait to make static method calls mockable in
tests:
http://3v4l.org/s5t3s
The issue can be avoided here by not using the "StaticCall" trait in subclasses of
"ChildClass" but in reality classes should just use the traits they need and not rely on
the trait usage of a parent class.
Is there an error on my side?
------------------------------------------------------------------------
[2011-09-05 07:32:09] tyrael@php.net
for the record: the segfault is caused by an infinite recursion (B->func), and
that happens, because the $this in the B->func() points to C, which causes
parent::func to point to itself.
btw. I find it really unintentional that call_user_func can be used with both
passing an object instance and a static call reference as a method name.
we also have failing tests for this particular bug:
Zend/tests/bug48770.phpt
Zend/tests/bug48770_2.phpt
Zend/tests/bug48770_3.phpt
imo as we have this behavior for some time now, I think we should keep it, and
update the tests.
Tyrael
------------------------------------------------------------------------
[2009-09-25 12:12:12] dmitry dot revenko at businessmedia dot ru
I'm sorry.
The solution is:
call_user_func_array('parent::func', $args);
instead of
call_user_func_array(array($this, 'parent::func'), $args);
------------------------------------------------------------------------
[2009-09-25 08:08:07] dmitry dot revenko at businessmedia dot ru
I also used this pattern in some critical moments, and it proved to be very useful.
Yes, I know about PHP 3's "call_user_func() now propagates $this even if the callee is the
parent class". But I don't know - why? Why so simple working logic was ruined in new
version? Isn't it straght that call_user_func_array(array( $this, 'parent::func' ),
$args) should call first found parent method func?
------------------------------------------------------------------------
[2009-08-01 01:51:07] jani@php.net
Also note: This works fine with PHP_5_2 :)
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=48770
--
Edit this bug report at https://bugs.php.net/bug.php?id=48770&edit=1