On Mon, Feb 16, 2015 at 9:50 PM, François Laupretre <franc...@php.net> wrote:
>> De : Pavel Kouril [mailto:pajou...@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
>

Hello,

finally got to this, after a while of thinking - the first part was
answered before, so I'll get only to the str_replace now. :)

Basically, each of the 8 different version based on parameters does
different thing, if I'm counting it correctly. So having 8 different
declarations is IMHO valid. I know it sounds a little bit weird, but
if you really realize the amount of things the function is doing based
on the passed parameters, why would having one declaration with
multiple argument types and if statements deciding what to do based on
an argument types be better than 8 different declarations, where each
one does one predictable thing and can be documented separately? :)


PS: I know there's something like a declined RFC for method
overloading in the wiki (actually, just a 7 years old email), but if
there would be someone who would be interested in having method
overloading in PHP and understands PHP's internals (I don't) so he'd
be able to make the implementation, I'd like to discuss this idea with
him more and contribute somehow to a possible RFC.

Regards
Pavel Kouril

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to