forked from krakjoe/pthreads
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
196 additions
and
42 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,100 @@ | ||
--TEST-- | ||
Basic anonymous class support, fix #505 | ||
--DESCRIPTION-- | ||
Unbound anon class causing segfaults, we delay copy but still cannot serialize the anon | ||
--FILE-- | ||
<?php | ||
class Test extends Thread { | ||
/** | ||
* doccomment run | ||
*/ | ||
public function run() { | ||
$this->alive = true; | ||
|
||
/** | ||
* doccomment anonymous | ||
*/ | ||
$this->anonymous = new class extends Thread { | ||
const CONSTANT = 'constant'; | ||
|
||
/** | ||
* @var | ||
*/ | ||
public $pubProp; | ||
|
||
protected $protProp; | ||
|
||
private $privProp; | ||
|
||
public static $staticProp; | ||
|
||
public function run() { | ||
var_dump('anonymous run'); | ||
$this->ready = true; | ||
} | ||
|
||
public function method() { | ||
var_dump('method executed'); | ||
} | ||
|
||
public static function staticMethod() {} | ||
}; | ||
|
||
var_dump($this->anonymous); | ||
|
||
$this->anonymous->start(); | ||
$this->anonymous->join(); | ||
|
||
while($this->alive) {} | ||
} | ||
} | ||
$test = new Test(); | ||
$test->start(); | ||
|
||
while(true) { | ||
if(isset($test->anonymous, $test->anonymous->ready)) { | ||
var_dump($test->anonymous); | ||
|
||
$test->anonymous->run(); | ||
$test->anonymous->method(); | ||
/* | ||
$class = new ReflectionClass($test->anonymous); | ||
var_dump($class); | ||
var_dump($class->getConstants()); | ||
//var_dump($class->getMethods()); | ||
var_dump($class->getProperties()); | ||
$class->setStaticPropertyValue('staticProp', 'property injected'); | ||
var_dump($class->getStaticProperties()); | ||
*/ | ||
$test->alive = false; | ||
break; | ||
} | ||
} | ||
$test->join(); | ||
--EXPECT-- | ||
object(class@anonymous)#2 (3) { | ||
["pubProp"]=> | ||
NULL | ||
["protProp"]=> | ||
NULL | ||
["privProp"]=> | ||
NULL | ||
} | ||
string(13) "anonymous run" | ||
object(class@anonymous)#2 (4) { | ||
["pubProp"]=> | ||
NULL | ||
["protProp"]=> | ||
NULL | ||
["privProp"]=> | ||
NULL | ||
["ready"]=> | ||
bool(true) | ||
} | ||
string(13) "anonymous run" | ||
string(15) "method executed" |
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,20 @@ | ||
--TEST-- | ||
Test fix for #658 with inheritance | ||
--DESCRIPTION-- | ||
Unbound anon class causing segfaults, we delay copy but still cannot serialize the anon | ||
--FILE-- | ||
<?php | ||
$task = new class extends Thread { | ||
|
||
public function run() | ||
{ | ||
$this->prop = new class extends Threaded {}; | ||
|
||
var_dump($this->prop); | ||
} | ||
}; | ||
|
||
$task->start() && $task->join(); | ||
--EXPECT-- | ||
object(class@anonymous)#2 (0) { | ||
} |
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,19 @@ | ||
--TEST-- | ||
Test fix for #659 | ||
--DESCRIPTION-- | ||
Unbound anon class causing segfaults, we delay copy but still cannot serialize the anon | ||
--FILE-- | ||
<?php | ||
$task = new class extends Thread { | ||
|
||
public function run() | ||
{ | ||
$this->prop = new class {}; | ||
|
||
var_dump($this->prop); /* we do expect null: anon classes cannot be serialized */ | ||
} | ||
}; | ||
|
||
$task->start() && $task->join(); | ||
--EXPECT-- | ||
NULL |