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
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: david@php.net
New email:
PHP Version: OS:

 

 [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 Jun 02 07:01:30 2024 UTC