php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70997 When using parentClass:: instead of parent::, static context changed.
Submitted: 2015-11-30 09:29 UTC Modified: 2015-11-30 13:56 UTC
From: arjen at parse dot nl Assigned: dmitry
Status: Closed Package: Scripting Engine problem
PHP Version: 7.0.0RC8 OS: Linux
Private report: No CVE-ID:
 [2015-11-30 09:29 UTC] arjen at parse dot nl
Description:
------------
Compared to 5.x. Behaviour of LSB (?) changed, bug or not documented?
I cannot find anything about this subtle change in the 7.0 migration guide (http://php.net/manual/en/migration70.incompatible.php) nor in the 7.0 NEWS file.

See https://3v4l.org/edVna

I know it's easy to fix in the codebase, but it would be nice if this changed is documented when intended or original behavior restored.

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

class A {
    const TEST = false;
    
    public function test()
    {
        var_dump(static::TEST);
    }
}

class B extends A {
    const TEST = true;
    
    public function test()
    {
        A::test();
    }
}

$b = new B;
$b->test();

Expected result:
----------------
bool(true)

Actual result:
--------------
bool(false)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-11-30 10:51 UTC] laruence@php.net
-Package: Scripting Engine problem +Package: Documentation problem
 [2015-11-30 10:51 UTC] laruence@php.net
I think this is not a bug, but a improvement, as you already call explicit A::test, which means, you are expecting A's scope ..

so, change to document problem.

thanks
 [2015-11-30 13:54 UTC] dmitry@php.net
Automatic comment on behalf of dmitry@zend.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=25c5d185fcece7620f4b1790fd705999757f3b2f
Log: Fixed bug #70997 (When using parentClass:: instead of parent::, static context changed)
 [2015-11-30 13:54 UTC] dmitry@php.net
-Status: Open +Status: Closed
 [2015-11-30 13:56 UTC] dmitry@php.net
-Package: Documentation problem +Package: Scripting Engine problem -Assigned To: +Assigned To: dmitry
 [2016-07-20 11:35 UTC] davey@php.net
Automatic comment on behalf of dmitry@zend.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=25c5d185fcece7620f4b1790fd705999757f3b2f
Log: Fixed bug #70997 (When using parentClass:: instead of parent::, static context changed)
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Wed Apr 26 02:01:38 2017 UTC