php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69007 scope resolution doesn't work with static anonymous functions
Submitted: 2015-02-07 21:25 UTC Modified: 2016-05-12 16:09 UTC
From: minecraftshamrock at gmail dot com Assigned: nikic (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: master-Git-2015-05-28 (Git) OS:
Private report: No CVE-ID: None
 [2015-02-07 21:25 UTC] minecraftshamrock at gmail dot com
Description:
------------
Scope resolution using parent:: self:: and static:: does not work properly and is poorly specified for static anonymous functions.

Test snippet:
http://pastebin.com/7y9Wa4Xj

I have neither found a prediction by the specification about how this should behave, nor were I able to interpret any rules into the behavior when testing.

I've tested the linked script using http://3v4l.org/ in various versions of PHP and no version of PHP exhibits a logically reasonable behavior (except HHVM). 

So please specify more exactly how this should behave and implement it in PHP.

Expected result:
----------------
Actually none because the specification predicts nothing about this code.

Actual result:
--------------
Output for 5.5.14 - 5.6.5, php7@20140701 - 20150201

    GuyGuy
    ChildChild
    FatherFather
    Child
    GuyChildChild
    GuyGuy

Note that for this versions "self::hi();" and "echo self::class;" in the static anonymous function do not even refer to the same class as "self".

Output for 5.5.0 - 5.5.13, php7@20140507 - 20140521

    GuyGuy
    ChildChild
    FatherFather
    Guy
    GuyGuyGuy
    FatherFather


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-02-20 00:20 UTC] aharvey@php.net
-Package: *General Issues +Package: PHP Language Specification
 [2015-06-28 21:01 UTC] stas@php.net
-Package: PHP Language Specification +Package: Scripting Engine problem -PHP Version: Irrelevant +PHP Version: master-Git-2015-05-28 (Git)
 [2016-05-12 16:09 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2016-05-12 16:09 UTC] nikic@php.net
Since PHP 7 the behavior is consistent with HHVM and follows "works the same as outside the closure".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 06 05:01:31 2024 UTC