|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #4582 `unset' removes the effect of `global'
Submitted: 2000-05-24 20:20 UTC Modified: 2000-05-26 18:42 UTC
From: massaro at ime dot usp dot br Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0.0 Release OS: Linux
Private report: No CVE-ID: None
 [2000-05-24 20:20 UTC] massaro at ime dot usp dot br
function change()
  global $var;
  $var = 'after';
$var = 'before';
print $var . "<br>\n";

PHP3 prints "after", but PHP4 prints "before". If the line "unset($var);" in the function is removed, both print "after".

Looks like `unset' is removing the effect of the `global'.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2000-05-26 18:42 UTC] joey at cvs dot php dot net
This is the proper behavior.

unset() is removing the reference from $var in the 
scope of change() to the value of $GLOBALS["var"].
This is documented in the incompat. list, but I will make
it more clear.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Tue Mar 02 12:01:23 2021 UTC