Req #80153 [Opn]: ReflectionMethod should have a method to translate the "self" return type

From: Date: Fri, 10 Sep 2021 10:33:06 +0000
Subject: Req #80153 [Opn]: ReflectionMethod should have a method to translate the "self" return type
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-236517@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80153&edit=1 ID: 80153 Updated by: cmb@php.net Reported by: spychala dot adam at gmail dot com Summary: ReflectionMethod should have a method to translate the "self" return type Status: Open Type: Feature/Change Request Package: Class/Object related Operating System: Ubuntu PHP Version: 7.4.10 Block user comment: N Private report: N New Comment: > But a new method to return the "effective" type sounds like a > reasonable request to me. I have doubts about that, because it's not hard to resolve that for self in userland code, and for static it would not be possible at all to have such a method (unless it accepted the LSB type, in which case it would not be hard to resolve that in userland, too). Previous Comments: ------------------------------------------------------------------------ [2020-09-26 22:53:41] requinix@php.net Ah. In that case, > Shouldn't it return then 'B', not 'self'? I don't think so. Reflection isn't just about how code behaves but about how it was written, and if the method was written to return "self" then that is what reflection should say. But a new method to return the "effective" type sounds like a reasonable request to me. ------------------------------------------------------------------------ [2020-09-26 22:21:26] spychala dot adam at gmail dot com I'm sorry. Repeated mistake. I thought of 'B' and typed 'A'. I agree with that > If getReturnType() returned "B" then the fact that the method actually is supposed to > return "self" is lost. It should be another method for returning specific return type, because we also miss such information with self/static return types. ------------------------------------------------------------------------ [2020-09-26 21:29:35] requinix@php.net > Self is not type in PHP, is keyword. self is most definitely a type. You can use it in every situation I can think of that wants a type: parameter types, return types, instanceof a type, creating a new instance of a type... It is *also* a keyword. > Shouldn't it return then 'A', not 'self'? Like I said before, no. Please read what I said. ------------------------------------------------------------------------ [2020-09-26 20:38:47] spychala dot adam at gmail dot com Shouldn't it return then 'A', not 'self'? Self is not type in PHP, is keyword. ------------------------------------------------------------------------ [2020-09-26 19:33:35] requinix@php.net "self" means self. It does not mean "A" or "B". Which means your expected result is incorrect: B's getSomething needs to return an instance of B, not of A. https://3v4l.org/YLDaH If getReturnType() returned "B" then the fact that the method actually is supposed to return "self" is lost. If you need to know that B::getSomething() must return an instance of B then I suggest: if ($return_type == 'self') { $return_type = 'B'; } ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=80153 -- Edit this bug report at https://bugs.php.net/bug.php?id=80153&edit=1

« previous php.bugs (#236517) next »