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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
5 + 14 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 11:01:28 2024 UTC