php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #34865 static unset documentation is unclear
Submitted: 2005-10-14 04:23 UTC Modified: 2005-11-03 12:00 UTC
From: david at tulloh dot id dot au Assigned:
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2005-10-14 04:23 UTC] david at tulloh dot id dot au
Description:
------------
http://www.php.net/manual/en/function.unset.php#AEN183845

The documentation for unsetting static variables is very unclear and confusing due to it's contradictory nature.

It is stated that the variable is destroyed, yet the example shows that this clearly isn't the case.  Rather the variable is only temporarily destroyed, for the remainder of that function.

The example provided seems to demonstrate that unset has no effect, removing the unset command produces exactly the same output.

I believe changing the descriptive text and changing the example to something like the one below would make the behaviour far clearer.

Reproduce code:
---------------
<?php
function foo() {
    static $bar;
    $bar++;
    echo "Before unset: $bar\n";
    unset($bar);
    $bar = 23;
    echo "After unset: $bar\n";
}
foo();
foo();
foo();
?>

Before unset: 1
After unset: 23
Before unset: 2
After unset: 23
Before unset: 3
After unset: 23



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-11-03 12:00 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

"If a static variable is unset() inside of a function, unset() destroys the variable only in the context of the rest of a function. Following calls will restore the value of a variable." + fixed example.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 15 06:01:33 2025 UTC