|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2021-02-17 18:15 UTC] bernievbb at icloud dot com
Description:
------------
class and method are lost when __METHOD__ called in closure.
Test script:
---------------
<?php
namespace pdox\pal;
class test
{
function test1()
{
var_dump(__METHOD__); // string(21) "pdox\pal\test::test1"
$a = function() {return __METHOD__;};
var_dump($a()); // string(18) "pdox\pal\{closure}"
$b = fn() => __METHOD__;
var_dump($b()); // string(18) "pdox\pal\{closure}"
}
}?>
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 08 23:00:01 2025 UTC |
Clearly __METHOD__ is NOT just a synonym for __FUNCTION__ ... All inside a namespaced class method: NOT in closure: __FUNCTION__ => method name __METHOD__ => namespace + className + "::" + methodName __CLASS__ => namespace + className IN a closure: __FUNCTION__ => namespace + "{closure}" __METHOD__ => namespace + "{closure}" __CLASS__ => namespace + className I would expect __METHOD__ to report the closure's parent method. To be consistent with not in a closure I would also reasonably expect __METHOD__ to provide the class name. __METHOD__ and __FUNCTION__ are useless in a closure. Surely this is not intended. I see no simple alternative. Think debugging, logging etc.