Re: [RFC] Invoke __callStatic when non-static public methods are called statically
| From: | Morgan | Date: | Sat, 30 Mar 2024 02:20:06 +0000 |
| Subject: | Re: [RFC] Invoke __callStatic when non-static public methods are called statically | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-122816@lists.php.net to get a copy of this message | ||
On 2024-03-30 13:06, 하늘아부지 wrote:
Even currently,I think the problem here is a confusion based on the idea that there is necessarily some direct correspondence between method names and strings passed to __callStatic. It's like confusing URLs with file paths. The fact that an object *may* have a private method named "foo" doesn't have any bearing on whether classname::foo() invokes __callStatic('foo') or not. The existence or otherwise of such methods in the class is irrelevant. __callStatic receives a string, and what it does with that string is entirely up to whoever is writing it. class First { protected static function test(): string { return "Calling First::test\n"; } } class Second extends First { public static function __callStatic(string $name, array $args): string { return "Calling callStatic::$name\n"; } public static function pass(): string { return Second::test(); // The inherited method } } echo Second::pass(); echo Second::test(); // Not the inherited method__callStaticis called in cases of non-static methods that are not public methods.__callStaticalready acts as a rule-breaker.