Am 09.03.2024 um 08:18 schrieb Marc <marc@mabe.berlin>: > As the pseudo type `mixed` exists since PHP 8.0, which is already > out-of-date, I have the feeling it would be better to force people to > explicitly write `mixed` to widen the type of an overwritten function and let > "no type" inherit the argument and return type of the parent. > > Example: > > class A { > public function typed(int $var): int { return $var; } > public function untyped($var) { return $var; } // implicit mixed as no > overwrite > } > class B extends A { > public function typed($var) { return $var; } // implicit int as inherited > from overwritten function > }
This sounds like a bad idea to me as I cannot look at the function definition in class B and determine what the type of $var is. On top of that: If the type of $var in A is changed then it would automatically also change in B. While this seems convenient it could also break B in subtle ways as the function suddenly gets different types than expected. Regards, - Chris