php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #18187 Consequent implementation of array referencing to user method
Submitted: 2002-07-05 11:46 UTC Modified: 2012-09-22 09:17 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: bram at totalgsm dot net Assigned: nikic (profile)
Status: Closed Package: *General Issues
PHP Version: 4.2.1 OS: any
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: bram at totalgsm dot net
New email:
PHP Version: OS:

 

 [2002-07-05 11:46 UTC] bram at totalgsm dot net
You support calling user methods using an array in the call_user_func() function. But related functions of call_user_func() don't support the syntax. I would like to see that function_exists could check if the user method exists. 

The following example code should work:

class Foo {
  function bar($what = 'world') {
    print 'Hello ' . $what;
  }
}

$a_foo = new Foo();

$user_method = array($a_foo, 'bar');

if (!function_exists($user_method)) 
  die('You shouldn\'t see this :)');

$user_method('PHP'); // Should print "Hello PHP" ofcourse.

Furthermore the implementation of the user_method calling in call_user_func is incorrect for referencing variabeles, which might be pretty usefull. (see http://bugs.php.net/bug.php?id=17309)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-09-22 09:17 UTC] nikic@php.net
-Status: Open +Status: Closed -Package: Feature/Change Request +Package: *General Issues -Assigned To: +Assigned To: nikic
 [2012-09-22 09:17 UTC] nikic@php.net
Closing as the $callable() syntax now works for array-callbacks too (as of PHP 5.4). Instead of function_exists the function is_callable can be used.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jul 04 17:01:35 2025 UTC