note 111982 rejected from class.closure by mazzanet

From: Date: Fri, 19 Apr 2013 04:57:47 +0000
Subject: note 111982 rejected from class.closure by mazzanet
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-194553@lists.php.net to get a copy of this message
Note Submitter: codexp at gmx dot net ---- how to find out the state of a closure? <?php class A {} $closure = function() { try { // maybe there is a better way to find it out if closure is standalone @$class = get_class(); } catch (Exception $e) { $class = false; } return $class ? isset($this) ? 'instance' : 'static' : 'standalone'; }; $cls = Closure::bind($closure, null, 'A'); $cli = Closure::bind($closure, new A, 'A'); echo $closure() . PHP_EOL; // standalone echo $cls() . PHP_EOL; // static echo $cli() . PHP_EOL; // instance ?>

« previous php.notes (#194553) next »