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

Pull Requests

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-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 17:01:31 2024 UTC