|  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: -
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 7.2.6 OS:
Private report: No CVE-ID: None
 [2018-06-08 09:43 UTC]
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:

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


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


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


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

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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-02-12 16:37 UTC]
Automatic comment on behalf of
Log: Fixed bug #76430
 [2019-02-12 16:37 UTC]
-Status: Open +Status: Closed
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Jul 19 15:01:28 2024 UTC