i got some problem with php multi thread,here is my code
<?php
class testClass {
const TEST = 'UTF-8';
public static $test1 = array(
'key' => 'value',
);
public static function test2() {
return "this is static func";
}
}
class My extends Thread {
public static $test3;
public static $test4 = "this is test4 string";
public function __construct() {
echo "main start
";
self::$test3 = new DateTime();
var_dump(testClass::TEST);
var_dump(testClass::$test1);
var_dump(testClass::test2());
var_dump(self::$test3);
var_dump(self::$test4);
echo "main end
";
}
public function run() {
echo "sub start
";
var_dump(testClass::TEST);
var_dump(testClass::$test1);
var_dump(testClass::test2());
var_dump(self::$test3);
var_dump(self::$test4);
echo "sub end
";
}
}
$my = new My();
$my->start();
?>
and the result
#main start
string(5) "UTF-8"
array(1) {
["key"]=>
string(5) "value"
}
string(19) "this is static func"
object(DateTime)#2 (3) {
["date"]=>
string(26) "2015-05-16 23:26:19.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(3) "PRC"
}
string(20) "this is test4 string"
#main end
#sub start
string(5) "UTF-8"
NULL
string(19) "this is static func"
NULL
string(20) "this is test4 string"
#sub end
in this result , you can see the static String variable can get the value from the sub Thread , but the DateTime object is not
sub Thread call testClass::TEST can get the value, but call testClass::$test1 is not
my PHP Version => 5.6.8 configure '--enable-maintainer-zts'
I am at my wits end, any help at all is greatly appreciated