|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #54130 call_user_func description is too general
Submitted: 2011-03-01 17:03 UTC Modified: 2012-01-07 18:24 UTC
From: ajrattink at correct dot net Assigned: frozenfire (profile)
Status: No Feedback Package: Documentation problem
PHP Version: 5.3.5 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: ajrattink at correct dot net
New email:
PHP Version: OS:


 [2011-03-01 17:03 UTC] ajrattink at correct dot net
From manual page:

The manual states that call_user_func(array($classname, $methname), ...) 
will call the static method of the class indicated by +classname+ but fails to mention that it does not work if the class is imported in a namespace. 
To avoid disappointed programmers, I think it should.

  use X as Y;
  call_user_func(array('Y', 'f'), ...) 

will not work. This means that if the original class caused a nameconflict there is absolutely no way of calling it. Ever.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-12-05 23:00 UTC]
-Status: Open +Status: Feedback -Assigned To: +Assigned To: frozenfire
 [2011-12-05 23:00 UTC]
So, just to clarify what you're saying: It's not currently possible to use 
call_user_func with a callback pointing to a static method in an imported class?

If that's the case, this seems more like a Zend bug than anything 
(zend_call_function is what handles these calls).
 [2012-01-07 18:24 UTC]
-Status: Feedback +Status: No Feedback
 [2012-01-07 23:25 UTC] hello at apfelbox dot net

I can confirm that call_user_func does not seem to mind namespaces:


namespace A;

class X {
	public static function f ()
		echo 'c';

call_user_func(array('X', 'f'));





Warning: call_user_func() expects parameter 1 to be a valid callback, class 'X' not found in ....


One comment to the last sentence of the original commenter:
there is a way: just use the fully qualified name, in my example

call_user_func(array('\A\X', 'f'));

will work as expected.
 [2012-01-07 23:27 UTC] hello at apfelbox dot net
Sorry, forgot to mention:
tested on OSX with PHP 5.3.6 (not the newest version, I know..)
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Jan 21 11:01:22 2021 UTC