php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #5884 Not able to unset($var) set as global in function
Submitted: 2000-07-31 23:29 UTC Modified: 2000-08-01 00:11 UTC
From: php42 at hotmail dot com Assigned:
Status: Closed Package: Other
PHP Version: 4.0.1pl2 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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: php42 at hotmail dot com
New email:
PHP Version: OS:

 

 [2000-07-31 23:29 UTC] php42 at hotmail dot com
<?
$test="test";

function foo() {
  global $test;
  $test = $test . " - foo";
  unset($test);
}

foo();
if (isset($test)) { echo "Set: $test"; } else { echo "Unset"; }
echo "<br>";
unset($test);
if (isset($test)) { echo "Set: $test"; } else { echo "Unset"; }

?> 

echos out:

Set: test - foo
Unset 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-08-01 00:11 UTC] waldschrott@php.net
taken from the php.net site:
"unset() now breaks the association between a locally scoped variable and one that is globally scoped if the reference is made using the "global" keyword."

I?ll not recommend you to touch the $GLOBALS array directly ;)
 
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Tue Jan 31 01:05:52 2023 UTC