php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #31930 is_callable / __call interaction
Submitted: 2005-02-11 08:45 UTC Modified: 2006-04-03 13:56 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: mcroghan at digitalkeg dot com Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 5.0.3 OS: RH3
Private report: No CVE-ID: None
 [2005-02-11 08:45 UTC] mcroghan at digitalkeg dot com
Description:
------------
Long story short, I created a class factory class.  I have singleton classes which this class handles beautifully, except for non-singleton classes which use __call.

All singleton classes have a method named "Singleton".  If this method exists, I invoke the Singleton method via call_user_func (which I noticed call_user_func doesn't route to __call, though that's in the bug DB).

Though I understand how __call is supposed to work and I love how it works, I feel there needs to be some sort of differentiation between classes that are explicitly defined in the class file vs what's being routed to __call.

I spent a good 3 hours scouring the online PHP documentation to find a solution that already exists for this, so my only assumption is that one doesn't exist.  It would be a real asset to the function is_callable (or a separate function) to be able to check for explicitly defined methods that do not use __call.

I think it is valuable to be able to have the option for is_callable to be able to detect methods that are callable via __call. I feel it is also absolutely necessary that methods that can't be called without __call can be detected properly as well. 

Reproduce code:
---------------
class CClass
{
   public function __constructor () {}

   public function __call ($_function, $_arguments)
   {}
}

$_className = 'CClass';

if (is_callable (array ($_className,'Singleton')))
	$class = call_user_func (array($_className, 'Singleton'));
else
	$class = new $_className ();

Expected result:
----------------
I would expect no fatal errors because PHP took a dump reporting singleton doesn't exist when hitting call_user_func.

Actual result:
--------------
Fatal error: Call to undefined method CURL_Wrapper::singleton() in /home/webos2/public_html/WebOS2/WebOS2.php on line 75

is_callable states the class method exists regardless of the situation when using __call in a class.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-04-03 13:56 UTC] tony2001@php.net
Works fine for me, considering fixed in 5.1.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Sep 19 06:01:27 2024 UTC