Req #76199 [Opn->Wfx]: __METHOD__ and Paamayim Nekudotayim

From: Date: Mon, 09 Apr 2018 02:25:07 +0000
Subject: Req #76199 [Opn->Wfx]: __METHOD__ and Paamayim Nekudotayim
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-214659@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76199&edit=1 ID: 76199 Updated by: requinix@php.net Reported by: valentiny510 at gmail dot com Summary: __METHOD__ and Paamayim Nekudotayim -Status: Open +Status: Wont fix Type: Feature/Change Request Package: *General Issues Operating System: X PHP Version: 7.2.4 Block user comment: N Private report: N New Comment: That won't work. https://3v4l.org/vav7G The double colon does not mean a static method call. It's called the "scope resolution operator", not the "static call operator". Whether a method call is instanced or static depends on how you call it. And the problem is that you're trying to call the method without using a particular instance. Consider: $test1 = new Test; $test2 = new Test; $method = $test1->n(5, true); If $method has "Test->n" then that doesn't do anything to tell PHP which instance of Test it should use to call the method. If you want to use a magic constant, use __FUNCTION__. https://3v4l.org/X42fU Previous Comments: ------------------------------------------------------------------------ [2018-04-08 18:29:50] valentiny510 at gmail dot com Description: ------------ __METHOD__ return the double colon inside the classes no matter what the scope is. I think it should return -> for non static methods. I know, I know.. is a very long shot and is somehow useless this scenario but... imagine the script below. Maybe would also avoid some confusions, for instance, if you want to debug and you just want to return the name of the method without executing it... Is not a big deal but anyways... Thank you Test script: --------------- class Test { function n($n, $return_method = false) { if ($return_method) return __METHOD__; return "N is $n"; } } $test = new Test; $method = $test->n(5, true); print $method . PHP_EOL; print $method(5) . PHP_EOL; Expected result: ---------------- Test::n N is 5 Actual result: -------------- Test::n Deprecated: Non-static method Test::n() should not be called statically N is 5 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=76199&edit=1

« previous php.bugs (#214659) next »