This repository has been archived by the owner on Dec 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 503
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copy closures defined by included classes
- Loading branch information
Showing
3 changed files
with
87 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
class ExternalClosureDefinition extends \Threaded { | ||
public function load() { | ||
$sync = function () { | ||
var_dump('Hello World'); | ||
}; | ||
$sync(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--TEST-- | ||
Closure copying of an included closure | ||
--DESCRIPTION-- | ||
We need to copy closures which are defined and bound by included classes | ||
--FILE-- | ||
<?php | ||
|
||
class Foo extends \Thread { | ||
/** @var bool */ | ||
public $running; | ||
|
||
/** @var \Threaded */ | ||
private $shared; | ||
|
||
public function __construct(\Threaded $shared) { | ||
$this->shared = $shared; | ||
} | ||
|
||
public function run() { | ||
$this->running = true; | ||
|
||
require __DIR__ .'/assets/ExternalClosureDefinition.php'; | ||
|
||
$this->shared['loader'] = new ExternalClosureDefinition(); | ||
$this->synchronized(function () { | ||
while($this->running) { | ||
$this->wait(0); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
$shared = new \Threaded(); | ||
|
||
$foo = new Foo($shared); | ||
$foo->start(); | ||
|
||
while(true) { | ||
if(!isset($shared['loader'])) { | ||
continue; | ||
} | ||
$closureDefinition = $shared['loader']; | ||
$closureDefinition->load(); | ||
break; | ||
} | ||
$foo->running = false; | ||
$foo->notify() && $foo->join(); | ||
--EXPECT-- | ||
string(11) "Hello World" |
This seems wasteful. Wouldn't it make more sense to simply copy closures after copying classes?