Bug #74198 [NEW]: Local static variable not update after create new object of class

From: Date: Thu, 02 Mar 2017 11:40:44 +0000
Subject: Bug #74198 [NEW]: Local static variable not update after create new object of class
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-207661@lists.php.net to get a copy of this message
From:             cca dot alexk at gmail dot com
Operating system: MacOS/Linux
PHP version:      7.1.2
Package:          Variables related
Bug Type:         Bug
Bug description:Local static variable not update after create new object of class

Description:
------------
Steps to reproduce:
1. Create object of class with method with local static variable
2. Assign value to this local variable
3. Create new object of that class
4. Check value of this variable


Test script:
---------------
<?php

class Foo
{
    protected $bar;
    
    public function __construct($bar)
    {
        $this->bar = $bar;
    }
    
    public function bar()
    {
        return $this->foo();
    }
    
    public function foo()
    {
        static $bar;
        if (!$bar) {
            $bar = $this->bar;
        }
        return $bar;
    }
}

var_dump((new Foo(123))->bar());
var_dump((new Foo(456))->bar());

Expected result:
----------------
int(123)
int(456)

Actual result:
--------------
int(123)
int(123)

-- 
Edit bug report at https://bugs.php.net/bug.php?id=74198&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=74198&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=74198&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=74198&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=74198&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=74198&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=74198&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=74198&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=74198&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=74198&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=74198&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=74198&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=74198&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=74198&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74198&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=74198&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=74198&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=74198&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=74198&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=74198&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=74198&r=mysqlcfg



Thread (1 message)

  • cca dot alexk at gmail dot com
« previous php.bugs (#207661) next »