|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2013-12-11 06:09 UTC] vGhost2000 at gmail dot com
Description:
------------
When thread class create in static property, object destroy when start.
Test script:
---------------
<?php
TestController::init();// bug;
new TestControllerV2; // not bug
class TestController
{
public static $count = 10;
protected static $_threads = array();
public static function init()
{
for ($i = 0; $i < static::$count; $i++) {
static::$_threads[$i] = new TestThread;
static::$_threads[$i]->start();
}
print_r(static::$_threads);
}
}
class TestControllerV2
{
public static $count = 10;
protected $_threads = array();
public function __construct()
{
for ($i = 0; $i < static::$count; $i++) {
$this->_threads[$i] = new TestThread;
$this->_threads[$i]->start();
}
print_r($this->_threads);
}
}
class TestThread extends Thread
{
public function run()
{
sleep(5);
}
}
Expected result:
----------------
First array with TestThread Object, not null.
Actual result:
--------------
Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
)
Array
(
[0] => TestThread Object
(
)
[1] => TestThread Object
(
)
[2] => TestThread Object
(
)
[3] => TestThread Object
(
)
[4] => TestThread Object
(
)
[5] => TestThread Object
(
)
[6] => TestThread Object
(
)
[7] => TestThread Object
(
)
[8] => TestThread Object
(
)
[9] => TestThread Object
(
)
)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 19 06:00:01 2025 UTC |
exactly speaking, the threads do not crash. They just can not be referenced. They can work well while they can not be var_dumped class TestThread extends Thread { public function run() { sleep(5); echo $this->getThreadid() , "\n"; } } If the threads look like above, their thread ids will echo to screen after 5 secs