|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-04-03 13:56 UTC] tony2001@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 10:00:01 2025 UTC |
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.