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 >
I will get to this more tomorrow, but now just a short notes: I'd only have tan(float) with int being able to be passed and the value would be implicitly converted to float. This is something even strongly typed languages normally do, and there is no reason PHP shouldn't be able to. If somebody would make a tan(float) and tan(int) declarations, then when calling tan($x), the apropriate one based on current type of $x should be called. I don't see any reason why this can be done only for strongly typed languages; could you name exact reasons? The str_replace(string|array $search, string|array $replace, string|array $subject[, int &$count ]) is a harder one to comment on though. I will refrain from answering on that one right now and will get back to that one tomorrow, because that one needs a little bit more thinking. Regards Pavel Kouril -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php