Bug #48770 [Com]: call_user_func_array() fails to call parent from inheriting class

From: Date: Fri, 17 Jul 2015 12:30:37 +0000
Subject: Bug #48770 [Com]: 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-194515@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 Comment by: mbrodala at pagemachine dot de Reported by: lumeet at yahoo dot com Summary: call_user_func_array() fails to call parent from inheriting class Status: Verified Type: Bug Package: Scripting Engine problem Operating System: * PHP Version: 5.3, 6 (2009-08-01) Block user comment: N Private report: N New Comment: 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? Previous Comments: ------------------------------------------------------------------------ [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 :) ------------------------------------------------------------------------ [2009-07-02 07:38:03] sjoerd-php at linuxonly dot nl Thank you for your bug report. I could reproduce it and added some more data: Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 0xb7d03b80 (LWP 6726)] 0x082dee15 in zend_is_callable_ex (callable=0x9e3cdc0, object_ptr=0x0, check_flags=0, callable_name=0x0, callable_name_len=0x0, fcc=0xbf49d190, error=0xbf49d0e8) at /home/sjoerd/dev/php/trunk/php5/Zend/zend_API.c:2624 2624 { #0 0x082dee15 in zend_is_callable_ex (callable=0x9e3cdc0, object_ptr=0x0, check_flags=0, callable_name=0x0, callable_name_len=0x0, fcc=0xbf49d190, error=0xbf49d0e8) at /home/sjoerd/dev/php/trunk/php5/Zend/zend_API.c:2624 #1 0x082df489 in zend_fcall_info_init (callable=0x9e3cdc0, check_flags=0, fci=0xbf49d16c, fcc=0xbf49d190, callable_name=0x0, error=0xbf49d0e8) at /home/sjoerd/dev/php/trunk/php5/Zend/zend_API.c:2858 #2 0x082e35a2 in zend_parse_va_args (num_args=2, type_spec=0x85b0091 "a/", va=0xbf49d13c, flags=0) at /home/sjoerd/dev/php/trunk/php5/Zend/zend_API.c:592 #3 0x082e3d12 in zend_parse_parameters (num_args=2, type_spec=0xbf49d0e8 "") at /home/sjoerd/dev/php/trunk/php5/Zend/zend_API.c:870 #4 0x08220dd1 in zif_call_user_func_array (ht=2, return_value=0x9e3ce7c, return_value_ptr=0x0, this_ptr=0x0, return_value_used=0) at /home/sjoerd/dev/php/trunk/php5/ext/standard/basic_functions.c:4748 #5 0x083259b9 in zend_do_fcall_common_helper_SPEC (execute_data=0x9de07bc) at /home/sjoerd/dev/php/trunk/php5/Zend/zend_vm_execute.h:313 #6 0x08302dbe in execute (op_array=0x9448e90) at /home/sjoerd/dev/php/trunk/php5/Zend/zend_vm_execute.h:104 #7 0x082d0c77 in zend_call_function (fci=0xbf49d37c, fci_cache=0xbf49d3a0) at /home/sjoerd/dev/php/trunk/php5/Zend/zend_execute_API.c:936 #8 0x08220df7 in zif_call_user_func_array (ht=2, return_value=0x9e3ccb0, return_value_ptr=0x0, this_ptr=0x0, return_value_used=0) at /home/sjoerd/dev/php/trunk/php5/ext/standard/basic_functions.c:4755 #9 0x083259b9 in zend_do_fcall_common_helper_SPEC (execute_data=0x9de06fc) at /home/sjoerd/dev/php/trunk/php5/Zend/zend_vm_execute.h:313 #10 0x08302dbe in execute (op_array=0x9448e90) at /home/sjoerd/dev/php/trunk/php5/Zend/zend_vm_execute.h:104 #11 0x082d0c77 in zend_call_function (fci=0xbf49d58c, fci_cache=0xbf49d5b0) at /home/sjoerd/dev/php/trunk/php5/Zend/zend_execute_API.c:936 #12 0x08220df7 in zif_call_user_func_array (ht=2, return_value=0x9e3cae4, return_value_ptr=0x0, this_ptr=0x0, return_value_used=0) at /home/sjoerd/dev/php/trunk/php5/ext/standard/basic_functions.c:4755 ... #11213 0x083259b9 in zend_do_fcall_common_helper_SPEC (execute_data=0x9c1d004) at /home/sjoerd/dev/php/trunk/php5/Zend/zend_vm_execute.h:313 #11214 0x08302dbe in execute (op_array=0x9448e90) at /home/sjoerd/dev/php/trunk/php5/Zend/zend_vm_execute.h:104 #11215 0x082d0c77 in zend_call_function (fci=0xbf60669c, fci_cache=0xbf6066c0) at /home/sjoerd/dev/php/trunk/php5/Zend/zend_execute_API.c:936 #11216 0x08220df7 in zif_call_user_func_array (ht=2, return_value=0x9c822d4, return_value_ptr=0x0, this_ptr=0x0, return_value_used=0) at /home/sjoerd/dev/php/trunk/php5/ext/standard/basic_functions.c:4755 #11217 0x083259b9 in zend_do_fcall_common_helper_SPEC (execute_data=0x9c1cf44) at /home/sjoerd/dev/php/trunk/php5/Zend/zend_vm_execute.h:313 #11218 0x08302dbe in execute (op_array=0x9448e90) at /home/sjoerd/dev/php/trunk/php5/Zend/zend_vm_execute.h:104 etc. etc. ------------------------------------------------------------------------ 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

« previous php.bugs (#194515) next »