On 06/06/2016 12:06, Dominic Grostate wrote:
float, int and string all share the same row on an upside down pyramid, with
$bar, being dynamic, at the bottom.
OK, so take away the dynamic case, and assume the caller is in weak
mode. Now you have a second case where you need priorities between the
types.
Or consider this code, which is already valid:
class A { function foo($bar) { echo "A: $bar"; } }
class B { function foo(int $bar) { echo "B: $bar"; } }
(new B)->foo(1.5); // B: 1
Or we could construct similar examples with parent and sub-classes as
the type constraint of $bar. And so on.
I tried to stress that this is an example of one detail among many that
would need to be worked out; I wasn't looking for a single answer.
Perhaps we would need to add a new keyword (or a native annotation?) to
mark that a function was overloaded, so that existing inheritance didn't
accidentally become overloading.
To my mind, this would add a lot of complexity to the language, and I'm
not convinced of the gain. If you want to avoid dynamically checking
variable types, you can always just provide separately named methods for
separate cases.
Regards,
--
Rowan Collins
[IMSoP]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php