ID: 28211
Updated by: [EMAIL PROTECTED]
Reported By: gk at proliberty dot com
-Status: Open
+Status: Wont fix
Bug Type: Feature/Change Request
Operating System: linux red hat 9
PHP Version: 4.3.4
New Comment:
Agreed, is_callable is suited for this.
Previous Comments:
------------------------------------------------------------------------
[2004-04-30 17:35:55] brad at info-link dot net
try using "callable":
<?php
class A { function foo() { } }
echo "A::foo is_callable? ". is_callable(Array('A', 'foo')) ."\n";
?>
Outputs:
A::foo is_callable? 1
So basically, this request should be re-bogusified...
------------------------------------------------------------------------
[2004-04-29 21:52:50] gk at proliberty dot com
method_exists() is not applicable in this case since it only accepts an
object, not the name of the class. There needs to be a way to check
existing of static methods, in the absence of a class instance since
you can call them and unavoidable fatal errors result if the function
doesn't exist. This is a serious limitation in the PHP language. I
don't know if PHP 5 addresses this.
Changed bug category to a feature request.
------------------------------------------------------------------------
[2004-04-29 15:22:26] [EMAIL PROTECTED]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php
You need to use method_exists() for object methods.
------------------------------------------------------------------------
[2004-04-29 00:46:07] gk at proliberty dot com
Description:
------------
function_exists() returns false on static functions
method_exists() won't work without an instance of object
many times i have a deep class hierarchy and subclasses need to call
inherited static methods. instances of each ancestor class in the
hierarchy do not generally exist so method_exists() doesn't solve the
problem.
If this is not a bug but a feature request, then it is also a
documentation bug since the manual does not mention that
function_exists() does not work with class member functions, which are
truly 'functions', not 'methods'. 'method' assumes a class instance.
[EMAIL PROTECTED] test]$ php -v
PHP 4.3.2-RC (cli) (built: Apr 25 2003 18:03:38)
Reproduce code:
---------------
<?php
class a {
function a(){
}
function static_func(){
echo ("a::static_func() - the static function really
exists!\n");
}
}
a::static_func();
$function_exists = function_exists("a::static_func") ? 'exists': 'does
not exist';
echo ("function_exists(\"a::static_func\") thinks that: \n");
echo("a::static_func() $function_exists\n");
$function_exists = function_exists("static_func") ? 'exists': 'does not
exist';
echo ("function_exists(\"static_func\") thinks that: \n");
echo("static_func() $function_exists\n");
?>
Expected result:
----------------
[EMAIL PROTECTED] test]$ php test.php
a::static_func() - the static function really exists!
function_exists("a::static_func") thinks that:
a::static_func() exists
function_exists("static_func") thinks that:
static_func() does not exist
Actual result:
--------------
[EMAIL PROTECTED] test]$ php test.php
a::static_func() - the static function really exists!
function_exists("a::static_func") thinks that:
a::static_func() does not exist
function_exists("static_func") thinks that:
static_func() does not exist
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=28211&edit=1