RE: [PHP-DEV] Reviving scalar type hints
| From: | François Laupretre | Date: | Mon, 16 Feb 2015 20:50:28 +0000 |
| Subject: | RE: [PHP-DEV] Reviving scalar type hints | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-82885@lists.php.net to get a copy of this message | ||
> De : Pavel Kouril [mailto:pajousek@gmail.com]
>
> Hello,
>
> I know this is probably a pretty unpopular opinion in PHP (based on
> the replies I got in the other thread), but different values for
> parameters should be IMHO solved by method overloading and such.
The question is not that it's unpopular, it's that 1. It requires strict types, and 2. If
we want to solve this by polymorphism, we must also support polymorphism on functions. Now, tell me
how you would solve the tan(int|float) case with polymorphism ? One 'tan' function for
int, one for float ? str_replace(string|array, string|array, string|array, int &) is also a nice
case to study if you can't sleep...
Sorry but polymorphism on scalar types is possible with strict types only, which is out of scope for
the next RFC.
François