Edit report at https://bugs.php.net/bug.php?id=48770&edit=1

 ID:                 48770
 Comment by:         tyr...@php.net
 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:

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


Previous Comments:
------------------------------------------------------------------------
[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] j...@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.

------------------------------------------------------------------------
[2009-07-02 07:28:31] lumeet at yahoo dot com

Description:
------------
When class C extends B, which extends A, calls from B to its parent 
methods fail when using call_user_func_array(). Using parent::func()
works just fine.

Reproduce code:
---------------
class A {
  function func( $str ) {
    echo $str;
  }
}

class B extends A {
  public function func( $str ) {
    call_user_func_array( array( $this, 'parent::func' ), array( $str ) );
  }
}

class C extends B {
  public function func( $str ) {
    parent::func( $str );
  }
}

$c = new C;
$c->func( 'This should work!' );

Expected result:
----------------
The code should output "This should work!".

Actual result:
--------------
PHP crashes with backtrace (yes, only one line):

Function     Arg 1     Arg 2     Arg 3   Source 
php5ts!zend_is_callable_ex+61e     011f0780     00000006     003228e0    


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=48770&edit=1

Reply via email to