PHP 4.0 Bug #3175: function_exists() only works for non-class member functions

From: Date: Tue, 11 Jan 2000 12:29:28 +0000
Subject: PHP 4.0 Bug #3175: function_exists() only works for non-class member functions
Groups: php.dev 
Request: Send a blank email to php-dev+get-14494@lists.php.net to get a copy of this message
From: apresence@hotmail.spam Operating system: Debian Linux 2.0.36 PHP version: 4.0 Beta 2 PHP Bug Type: Misbehaving function Bug description: function_exists() only works for non-class member functions Replace spam in my e-mail addy with .com (spam guard). I heard a nasty rumor that function_exists() should return true for class names, but it doesn't do that either. Suggestion: Provide a new function called class_function_exists() which when passed a class name (or maybe an instance of a class, but a class name seems to make more sense), and a function name defined only in that class, returns TRUE, otherwise FALSE. This would behave differently than function_exists(), even if it did work for class function names, in that it would return FALSE for functions not declared in global scope (See *A* below). Example code: <?php class Foo { function test() { return; } function function_exists($name) { return function_exists($name); } } function bar() { return; } function Baz() { return; } function showbool($bool) { echo ($bool ? "TRUE" : "FALSE") . "<BR>\n"; } echo "<HTML><BODY>\n"; // First, test functionality outside of a class showbool(function_exists('bar')); // TRUE (works) showbool(function_exists('Baz')); // TRUE (works, a comment on the documentation page said it didn't) showbool(function_exists('baz')); // TRUE (works, makes sense because function names are insensitive in PHP) showbool(function_exists('Foo')); // FALSE (doesn't work) showbool(function_exists('Foo->test')); // FALSE (doesn't work) // Now, test functionality inside of a class $foo = new Foo(); showbool($foo->function_exists('bar')); // TRUE (This makes sense because bar is a function declared in global scope, even though it is outside of the class) showbool($foo->function_exists('Foo')); // FALSE (didn't work, didn't expect it to, but tried it anyway) showbool($foo->function_exists('Foo->test')); // FALSE (didn't work, didn't expect it to, but tried it anyway) showbool($foo->function_exists('test')); // FALSE (seems like this should return TRUE) echo "</BODY></HTML>\n"; ?>

« previous php.dev (#14494) next »