php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63291 Global variables not working
Submitted: 2012-10-16 17:03 UTC Modified: 2012-10-18 20:57 UTC
From: chibisuke at web dot de Assigned: krakjoe (profile)
Status: Closed Package: pthreads (PECL)
PHP Version: 5.4.7 OS: FreeBSD
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: chibisuke at web dot de
New email:
PHP Version: OS:

 

 [2012-10-16 17:03 UTC] chibisuke at web dot de
Description:
------------
Global variables are not shared between threads, as real threads would do.

Test script:
---------------
<?php
class Test extends Thread {
    public function run() {
        $GLOBALS['x'] = 'bar';
    }
}

$x = "foo";

echo $x;
$thread = new Test();
echo $x;

$thread->start();
$thread->join();
?>


Expected result:
----------------
foobar

Actual result:
--------------
foofoo

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-10-16 17:07 UTC] chibisuke at web dot de
oups... uploaded the buggus testscript example....

fixed one:

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

class Test extends Thread {
    public function run() {
        $GLOBALS['x'] = 'bar';
    }
}

$x = "foo";

echo $x;
$thread = new Test();

$thread->start();
$thread->join();
echo $x;
?>

however the problem remains the same.
 [2012-10-18 20:57 UTC] krakjoe@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: krakjoe
 [2012-10-18 20:57 UTC] krakjoe@php.net
threads are not supposed to have access to global variables.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Thu Dec 12 06:01:24 2019 UTC