php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55789 Late Static Bindings
Submitted: 2011-09-26 23:18 UTC Modified: 2011-12-27 10:10 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: kashpur dot kostya at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3.8 OS: Windows7
Private report: No CVE-ID: None
 [2011-09-26 23:18 UTC] kashpur dot kostya at gmail dot com
Description:
------------
If I call method of the class "B" that implements class "A" that uses static, under some class "C" it tries to get static property of the "C", but not of the "B". And if I try to call B::inst() not under some class it works fine.

Test script:
---------------
class A
{
    public static $_a = null;

    private function __construct()
    {}

    private function __clone()
    {}

    public function inst()
    {
        if (is_null(static::$_a))
        {
            static::$_a = new static();
        }
        return static::$_a;
    }
}

class B extends A
{
    
}

class C
{
    public function __construct()
    {
         B::inst();
    }
}

Expected result:
----------------
B::$_a

Actual result:
--------------
Fatal error: Access to undeclared static property: C::$_a

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-11-16 00:12 UTC] felipe@php.net
-Package: Variables related +Package: Scripting Engine problem
 [2011-12-27 10:10 UTC] stas@php.net
-Status: Open +Status: Bogus
 [2011-12-27 10:10 UTC] stas@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Declare inst() as static if you call it statically. Otherwise PHP interprets it 
as a dynamic, which for BC reasons is allowed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jun 26 14:01:32 2024 UTC