#23150 [Bgs->Opn]: Using global $x, while $x is already global behaves in an inconsistent way

From: Date: Sat, 26 Apr 2003 21:34:16 +0000
Subject: #23150 [Bgs->Opn]: Using global $x, while $x is already global behaves in an inconsistent way
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-38480@lists.php.net to get a copy of this message
ID: 23150 Updated by: pollita@php.net Reported By: arattink at correct dot net -Status: Bogus +Status: Open -Bug Type: Scripting Engine problem +Bug Type: Feature/Change Request Operating System: Linux 2.4.16-4GB-SMP PHP Version: 4.3.1 New Comment: Reclassifying to Feature Request. Calling global in the global scope should not be done. It represents poor coding practices, however if someone on the Zend team wants to make this work (the basic problem is that the object is copied rather than referenced) here's the guys official feature request. Previous Comments: ------------------------------------------------------------------------ [2003-04-11 01:16:00] sniper@php.net . ------------------------------------------------------------------------ [2003-04-11 01:15:50] sniper@php.net Not bug, works just as expected. (Don't do this :) ------------------------------------------------------------------------ [2003-04-10 09:20:33] arattink at correct dot net I would expect that using $x1->f = 1234; would work the same if $x1 is declared explicitely as global or not, if it is already global, but: <? class X { var $f = 'PHP sucks'; }; $x1 = new X; $x2 = new X; $z1 = &$x1; $z2 = &$x2; { global $x1; $x1->f = 'PHP is OK!'; } { $x2->f = 'PHP is OK!'; } echo "x1.f=".$x1->f."\n"; echo "x2.f=".$x2->f."\n"; echo "z1.f=".$z1->f."\n"; echo "z2.f=".$z2->f."\n"; ?> shows this is not true. It seems that $z1 loses its reference to $x1, even though $x1 is never reassigned. Tested on php 4.2.2 and php 4.3.1, same results. List of modules: does not apply to this problem. Known workaround: don't do this... However, it can easily happen by mistake (as it did in our case). Yours sincerely, Arnoud Rattink. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=23150&edit=1

« previous php.bugs (#38480) next »