Hi Pavel, > On 12 Feb 2015, at 12:39, Pavel Kouřil <pajou...@gmail.com> wrote: > > I don't see any problem with combination of optional parameters with > method overloading. C# has it and it is pretty useful and works there > without any bigger issues. Sure, the dynamic typing may be a (small) > issue, but again, C# does it in an IMHO meaningful way as well and it > can be used as an inspiration, should this way be chosen.
C# also doesn’t have dynamic typing. Plus, adding overloading to an existing language is more difficult. > Overloading on scalar types - unpredictable how? Even with weak calls, > the best candidate could be chosen? Still likely to cause chaos. If you can overload based on scalar types, then foobar($a / 2) could call any of *three* different functions. > Of course, sometimes there will be > an abmbiguous call, but as long as there would be a way to define > which call you want, it shouldn't be a problem as well? “A way to define which call you want”? Sounds like a hacky workaround to me. > Poor API - for useland code or in PHP's functions itself? But I don't > think this should be considered as a real problem, because in userland > code, developers are able to create a poor API even with the current > versions of PHP. That doesn’t mean we should make it any easier. > If someone wants to shoot himself in the foot, he > will do it in one way or another. And at the same time, polymorphism > via method overloading can lead to a cleaner APIs, if it's used well. I don’t see how. The main things it enables are optional parameters (which we already support) and polymorphism (which we already support). So you’d have to explain what overloading brings to the table beyond those two things. > Well, about "number" type hint. How this would work, in combination > with strict types? > > function bar(float $f) { > return $f * 1.23; > } > > function foo(number $x) { > return bar($x); > } > > foo(1); > > From my understanding, it wouldn’t? It would accept an integer or a float, because both subclass number: function foobar(): number { return 1.0; // okay return 1; // okay } function foo(number $x) {} foo(1.0); // okay foo(1); // okay I don’t see why it “wouldn’t work”. -- Andrea Faulds http://ajf.me/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php