php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #331 static variables in object methods broken
Submitted: 1998-04-29 16:49 UTC Modified: 1998-04-29 17:50 UTC
From: jdavis at student dot net Assigned:
Status: Closed Package: Other
PHP Version: 3.0 Release Candidate 4 OS: linux
Private report: No CVE-ID: None
 [1998-04-29 16:49 UTC] jdavis at student dot net
sorry if i'm missing something but it would seem that the
following code should output:

1
2
3

instead $a never is set so it doesn't output anyting (except
the "<p>\n" part)

thank you and pls let me know if you need more info
-----

class foobar {

  function init () {   

    static $a=1;

    print $a;
    print "<p>\n";
  
    $a++;
    }
};

$bar = new foobar; $bar->init(); $bar->init();
$bar->init();

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1998-04-29 17:50 UTC] zeev
Fixed.  My recommendation to usually avoid using it stands.
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Mon May 23 23:05:47 2022 UTC