Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Test extends Thread
- {
- public $callbackVar;
- public function run()
- {
- $this->callbackVar->__invoke();
- }
- public function setClosure(Closure $callback)
- {
- $this->callbackVar = $callback;
- }
- public function setDeclarativeClosure()
- {
- $this->callbackVar = function()
- {
- echo "Declarative closure";
- };
- }
- public function rewrapClosure(Closure $callback)
- {
- $localCallback = function($c)
- {
- $_c = $c;
- return function() use ($_c)
- {
- $_c();
- };
- };
- $this->callbackVar = $localCallback($callback);
- }
- }
- error_reporting(0);
- $callbackVar = function()
- {
- echo "Callback var invoked.";
- };
- $test = new Test();
- $test->setClosure($callbackVar);
- assert($test->callbackVar === null, 'Callback is not null.');
- $test->callbackVar->__invoke();
- $test->start();
- $test->setDeclarativeClosure();
- assert($test->callbackVar === null, 'Callback is not null.');
- $test->callbackVar->__invoke();
- $test->start();
- $test->rewrapClosure($callbackVar);
- assert($test->callbackVar === null, 'Callback is not null.');
- $test->callbackVar->__invoke();
- $test->start();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement