On 2024-03-30 13:06, 하늘아부지 wrote:

Even currently, `__callStatic` is called in cases of non-static methods that are not public methods. `__callStatic` already acts as a rule-breaker.


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

Reply via email to