Req #50037 [Com]: No is_function() to check whether variable is an anonymous function

From: Date: Mon, 08 Nov 2010 22:49:58 +0000
Subject: Req #50037 [Com]: No is_function() to check whether variable is an anonymous function
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-155867@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=50037&edit=1 ID: 50037 Comment by: hn dot campbell at gmail dot com Reported by: mjs at beebo dot org Summary: No is_function() to check whether variable is an anonymous function Status: Bogus Type: Feature/Change Request Package: Feature/Change Request Operating System: OS X PHP Version: 5.3.0 Block user comment: N New Comment: Worth nothing here: as far as I can see there is no way to tell the difference between a Closure and a Functor (any class with an __invoke method) of some kind... both are objects, both are callable. The only detectable difference I can see is that you can't create a ReflectionFunction from a class - not a very useful test. Previous Comments: ------------------------------------------------------------------------ [2009-10-30 16:02:31] johannes@php.net Sorry, but your problem does not imply a bug in PHP itself. For a list of more appropriate places to ask for help using PHP, please visit http://www.php.net/support.php as this bug system is not the appropriate forum for asking support questions. Due to the volume of reports we can not explain in detail here why your report is not a bug. The support channels will be able to provide an explanation for you. Thank you for your interest in PHP. Use is_callable() ------------------------------------------------------------------------ [2009-10-29 21:24:42] mjs at beebo dot org Description: ------------ There doesn't seem to be any good way to check whether a variable is a closure/anonymous function. If $fn = function() { }; gettype($fn) is "object", and there is no is_function() or equivalent. The only way seems to be gettype($fn) == "object" && get_class($fn) == "Closure" but the anonymous function documentation says that the fact that anonymous functions have class Closure "is an implementation detail and should not be relied upon." I suggest: 1. gettype() returns "function" or "closure" when passed a closure. 2. is_function() is created that returns true when passed a closure, otherwise false. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=50037&edit=1

« previous php.bugs (#155867) next »