php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66261 Thread crush in static property
Submitted: 2013-12-11 06:09 UTC Modified: 2014-09-26 06:51 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: vGhost2000 at gmail dot com Assigned: krakjoe (profile)
Status: Closed Package: pthreads (PECL)
PHP Version: 5.5.6 OS: xUbuntu 12.04
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: vGhost2000 at gmail dot com
New email:
PHP Version: OS:

 

 [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
        (
        )

)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-12-30 12:27 UTC] hlxf0330 at 163 dot com
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
 [2014-09-26 06:51 UTC] krakjoe@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: krakjoe
 [2014-09-26 06:51 UTC] krakjoe@php.net
This was fixed in 2.0.8
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 17:01:31 2024 UTC