On Fri, Mar 29, 2024 at 3:41 AM 하늘아부지 <daddyof...@gmail.com> wrote:
>
> Hello.
>
> I created a wiki for __callStatic related issues.
> Please see:
> https://wiki.php.net/rfc/complete_callstatc_magic
>
> I look forward to your interest and advice.
>
> Best Regards.
> Daddyofsky

Hey there,

Some general feedback:

The RFC is a bit hard for me to follow, for example:

> However, the IDE cannot find active method, and the Go to Definition feature 
> cannot be used.

This sounds like a bug or feature request with your IDE, not a problem with PHP.

> This code is very clear, aside from the fact that the method is not static.

Clear to whom? As a developer this looks downright confusing. I can't
even guess what the actual behavior is. If you call a non-static
method statically, its currently an error. Why would this not be an
error?

> The IDE recognizes active methods well and the Go to definition feature also 
> works properly.

What is stopping the IDE to taking you to the __callStatic method?
That would be the correct behavior IMHO, not the implementation for
instance methods.

> Even if there are only a few core methods, it cannot be made into a single 
> file.

There is nothing stopping you from putting multiple classes in a file.

> As can be seen in the above examples, the code becomes clearer, and 
> navigation through the IDE works much better.

I completely disagree. It mixes concerns and makes spaghetti code into
incomprehensible code. Also, maybe you should take up IDE navigation
with your IDE?

> Instead of throwing an error when a non-static public method is called 
> statically, the _ _callStatic method should be invoked.

I completely agree with this, btw. Your examples could use some work
and shows all the reasons why it shouldn't call __callStatic(). A real
life example, that has nothing to do with a specific framework:

When generating proxies for existing types, you often need to share
some state between the proxies. To do that, you put static
methods/properties on the proxy class and hope to the PHP Gods that
nobody will ever accidentally name something in their concrete class
with the name you chose for things. To help with that, you create some
kind of insane prefix. If __callStatic() were called ALWAYS in a
static context, even if a non-static method exists, then collisions
would literally be impossible. But at that point, why can't I just
write:

class Test {
  public static function test(): string { return "hello world"; }
  public function test(): int { return random_int(); }
}

??? I feel like this is your real RFC and should be allowed if we're
allowed to __callStatic() to instance methods. I don't think it makes
sense to have one without the other, and then what you want with
__callStatic() comes naturally, instead of this weird and confusing
RFC.


Robert Landers
Software Engineer
Utrecht NL

Reply via email to