On Mon, Apr 12, 2021 at 3:15 PM Máté Kocsis <kocsismat...@gmail.com> wrote:

> Hi Nikita and Stanislav,
>
> >  > get_class(), get_parent_class() and get_called_class() without
>> argument
>> >
>> > I'm not sure why. I mean if we want to make them return the same as
>> > self::class etc. - up to the point of actually compiling them as such -
>> > no problem, but I don't see why they need to be deprecated. And I
>> > vaguely remember seeing get_class() at least a bunch of times in old
>> > code, when ::class didn't even exist. I don't see a good reason why that
>> > code should be broken.
>> >
>>
>> I agree with you on this one. From my perspective, there should be some
>> technical motivation for deprecations, and this one seems to be more about
>> coding style -- it removes an old way to write something, which has been
>> subsumed by a different construct in the meantime. I think Máté suggested
>> this one, maybe he can provide additional reasoning.
>>
>
> The technical motivation why I suggested this idea is because the optional
> parameter of get_class() and get_parent_class() doesn't have a correct
> default value
> since https://wiki.php.net/rfc/get_class_disallow_null_parameter. So I
> don't really mind
> the coding style perspective, I'd only like to ensure that default value
> handling is
> right without reverting the relevant RFC. If you think it's too much of a
> BC break for a
> small gain, then I'm ok to remove this item from the list.
>

Just to get a rough idea on how common these are, on the top 2k composer
packages:

$ rg -t php "get_class\(\)" sources/ | wc -l
379
$ rg -t php "get_parent_class\(\)" sources/ | wc -l
174
$ rg -t php "get_called_class\(\)" sources/ | wc -l
218

For get_class() and get_parent_class() a large fraction of uses seem to be
in generated code. get_parent_class() is almost always used to check if a
parent class exists, not get what it actually is. So the replacement for
that would be get_parent_class(self::class) rather than parent:class.
Here's the grep output if you want to take a look:
https://gist.github.com/nikic/12f963fbb4af9d0b2ef885a7417f6016

I don't have a strong opinion regarding the default value issue. It would
be nicer if we did not have functions with argument count dependent
behavior, but I also don't think it's a big deal in this case. These
functions are still rather benign -- they don't perform crazy signature
overloading like pg_query(), where it's impossible to express the signature
in normal PHP code anymore.

Overall I'm unsure the breakage is worthwhile here. Maybe someone else
wants to chime in as well.

Regards,
Nikita

Reply via email to