php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28674 'parent' and 'self' behave differently with call_user_func
Submitted: 2004-06-07 16:18 UTC Modified: 2004-09-08 04:53 UTC
From: nlhowell at cableone dot net Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5CVS-2004-06-07 (dev) OS: WinXP Pro 2600 SP1
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: nlhowell at cableone dot net
New email:
PHP Version: OS:

 

 [2004-06-07 16:18 UTC] nlhowell at cableone dot net
Description:
------------
If you use call_user_func(array("parent", "somefunc")), an error is triggered:
call_user_func(parent::x) [function.call-user-func.html]: First argument is expected to be a valid callback

However, doing this with 'self' instead of 'parent' works fine, and behaves as expected.

This may be a recurrence of Bug #26543, in which neither 'parent' nor 'self' could be used in call_user_func, so you might want to take a look at that.

Reproduce code:
---------------
<?php
class P { function __construct() { $args = func_get_args(); print_r($args); } }
class D { function __construct() { $args = func_get_args(); call_user_func_array(array("parent", "__construct")); } }
class C { function __construct() { $args = func_get_args(); call_user_func_array(array("self", "func"), $args); } function func() { $args = func_get_args(); print_r($args); } }
$c = new C(1,2,3,4); // behaves as expected
$d = new D(1,2,3,4); // doesn't behave as expected
?>

Expected result:
----------------
Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 ) 
Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 ) 

Actual result:
--------------
Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 ) 
Warning: call_user_func(parent::x) [function.call-user-func.html]: First argument is expected to be a valid callback in c:\Inetpub\wwwroot\test.php5 on line 3

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-09-08 04:53 UTC] curt@php.net
In order to use 'parent' the calling class must be extended from a class, and have the method defined.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 11:01:30 2024 UTC