Re: Constructor promoted property and default value
| From: | Pierre | Date: | Mon, 23 Oct 2023 15:27:05 +0000 |
| Subject: | Re: Constructor promoted property and default value | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-121445@lists.php.net to get a copy of this message | ||
Le 23/10/2023 à 17:16, Larry Garfield a écrit :
Where this becomes a problem is readonly properties, since those are not allowed to have default values. (That would make them constants with worse performance.) A solution would need to be able to detect that the parent::__construct() isn't called, and then call it anyway, or at least partially call it. Unfortunately, I can think of many cases where such a call would result in unexpected behavior. It might be possible to resolve, but it's definitely not simple, and it could easily lead to weird behavior. --Larry GarfieldThanks for the explanation ! I see, there is no easy answer, yet current state is, in my opinion, unintuitive for developers, and eventually unsatisfying when falling in this trap. That's sad that readonly properties make this not trivial. Maybe some kind of object construct-post-hook could detect those case and affect variables with default values ? I don't know enough PHP internals to give a rational answer to this problem through... Regards, -- Pierre