From:             pretzlaw at gmail dot com
Operating system: Ubuntu 12.10 L 3.5.0-27-generic
PHP version:      5.4.14
Package:          *General Issues
Bug Type:         Bug
Bug description:Static methods with static variables keep their value

Description:
------------
Inherit a class with a static method. The static method has static variable
in 
it. Now execute both methods and watch the variable. It wont change from
one 
class to another.

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

class A
{
    function __construct()
    {
        echo get_class($this->getInstance()), PHP_EOL,
                get_class(static::getInstance()), PHP_EOL,
                get_class(self::getInstance()), PHP_EOL;
    }

    public static function getInstance()
    {
        static $getInstance;

        if (null == $getInstance) $getInstance = self::makeInstance();

        return $getInstance;
    }

    public static function makeInstance()
    {
        return new stdClass();
    }
}

$a = new A();

class B extends A
{
    function __construct()
    {
        echo get_class($this->getInstance()), PHP_EOL,
                get_class(static::getInstance()), PHP_EOL,
                get_class(self::getInstance()), PHP_EOL;
    }

    public static function makeInstance()
    {
        return new ArrayObject();
    }
}

$a = new B();

Expected result:
----------------
stdClass
stdClass
stdClass
ArrayObject
ArrayObject
stdClass

Actual result:
--------------
stdClass
stdClass
stdClass
stdClass
stdClass
stdClass

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

Reply via email to