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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: massaro at ime dot usp dot br
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Wed Feb 05 15:01:32 2025 UTC