php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #7137 The unset function doesn't work inside a funcfion for a global var
Submitted: 2000-10-11 11:37 UTC Modified: 2000-10-11 11:56 UTC
From: laszloj at psi dot com Assigned:
Status: Closed Package: Variables related
PHP Version: 4.0.2 OS:
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: laszloj at psi dot com
New email:
PHP Version: OS:

 

 [2000-10-11 11:37 UTC] laszloj at psi dot com
<?
 function xx() {
  global $a;
  unset($a);
 }

 // stage 1 - unset works
 $a=1;
 print "a= $a<br>";
 unset($a);
 print "a= $a<br>";
 // stage 2 - unset doesn't work in function xx
 $a=2;
 print "a= $a<br>";
 xx();
 print "a= $a<br>";

?>

My Result page:
a= 1
a= 
a= 2
a= 2  - it has to be empty because of previous unset

This script is working with PHP3.x

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-10-11 11:56 UTC] stas@php.net
FAQ. You cannot unset global. You should unset $GLOBALS["a"]. Please read "References Explained" in the manual, especially "Spotting References" and "Unsetting references".
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue May 13 10:01:27 2025 UTC