|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 17 14:00:02 2025 UTC |
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.