php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #13967 unset() on a static variable causes it to forget it is static
Submitted: 2001-11-06 21:49 UTC Modified: 2001-12-12 18:01 UTC
From: david@php.net Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.0.6 OS: Debian Linux
Private report: No CVE-ID: None
 [2001-11-06 21:49 UTC] david@php.net
Doing unset() on a static variable causes it to forget the fact that it is static for the rest of the function.

e.g.

<?
function abc() {
  static $a = 123;
  echo "On entry, a = $a\n";
  unset($a);
  $a = 456;
}

abc();
abc();
?>

should give 123 then 456. It gives 123 and 123.

Replacing unset($a) with $a = null, or removing the unset() entirely has the desired result of giving 123 then 456.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-11-07 18:29 UTC] jeroen@php.net
Like with global, static is a keyword linking a variable specially. unset() will completely destroy the variable with all links it might have. This is expected behaviour, or at least a known side-effect. With the current way of handling variables internally, this is not going to change.

This isn't stressen enough in the manual, so changing to documentation problem.
 [2001-12-12 18:01 UTC] jan@php.net
fixed in CVS
 [2020-02-07 06:12 UTC] phpdocbot@php.net
Automatic comment on behalf of jan
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=229da4ff5a81eb45ccab4b3b97d2f91fced4f052
Log: fixed #13967 unsetting a static varible inside a function destryoes the variable.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 19 00:01:33 2024 UTC