php.net |  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
<?php
function change()
{
  global $var;
  unset($var);
  $var = 'after';
}
$var = 'before';
change();
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'.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 06:01:30 2024 UTC