note 111982 added to class.closure
| From: | codexp at gmx dot net | Date: | Thu, 18 Apr 2013 22:15:41 +0000 |
| Subject: | note 111982 added to class.closure | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-194547@lists.php.net to get a copy of this message | ||
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
?>
----
Server IP: 87.106.1.137
Probable Submitter: 188.108.65.208
----
Manual Page -- http://php.net/manual/en/class.closure.php
Edit -- https://master.php.net/note/edit/111982
Del: integrated -- https://master.php.net/note/delete/111982/integrated
Del: useless -- https://master.php.net/note/delete/111982/useless
Del: bad code -- https://master.php.net/note/delete/111982/bad+code
Del: spam -- https://master.php.net/note/delete/111982/spam
Del: non-english -- https://master.php.net/note/delete/111982/non-english
Del: in docs -- https://master.php.net/note/delete/111982/in+docs
Del: other reasons-- https://master.php.net/note/delete/111982
Reject -- https://master.php.net/note/reject/111982
Search -- https://master.php.net/manage/user-notes.php