php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76430 __METHOD__ inconsistent outside of method
Submitted: 2018-06-08 09:43 UTC Modified: -
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: nikic@php.net Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 7.2.6 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: nikic@php.net
New email:
PHP Version: OS:

 

 [2018-06-08 09:43 UTC] nikic@php.net
Description:
------------
When __METHOD__ is used outside a method, but inside a class, it currently either returns the name of the class, or the name of the wrapping function, if the class is defined inside a function.

There are three possible results that would be consistent, though I think the best one would be to return an empty string in both cases, as we are logically not inside a method or function -- the class declaration separates the scope.

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

class Foo {
    const X = __METHOD__;
}
function foo() {
    class Bar {
        const X = __METHOD__;
    }
}

foo();
var_dump(Foo::X);
var_dump(Bar::X);

Expected result:
----------------
string(0) ""
string(0) ""

or

string(3) "Foo"
string(3) "Bar"

or

string(0) ""
string(3) "foo"

Actual result:
--------------
string(3) "Foo"
string(3) "foo"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-02-12 16:37 UTC] nikic@php.net
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=93641539429c41a8997016ee4a4502882b0a722e
Log: Fixed bug #76430
 [2019-02-12 16:37 UTC] nikic@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 08:02:42 2024 UTC