Derick Rethans wrote:

> On Mon, 6 Jun 2016, Dominic Grostate wrote:
> 
>> As I understand it, using Java-like function overloading in PHP is
>> undesirable due to hindrance in readability.
> 
> Besides it impacting, readability, it will also create a large impact on 
> performance.
> 
> Right now, functions (and methods) are looked up by their name only. In 
> order to support function overloading, the argument's types also need to 
> be taken into account. In C++, it works by mangling function names by 
> adding markers for types, such as:
> 
>       _ZN4HPHP34c_MongoDBDriverCursor_ni_getServerEPNS_10ObjectDataE
> 
> which means:
> 
>       HPHP::c_MongoDBDriverCursor_ni_getServer(HPHP::ObjectData*)
> 
> But unlike in C++, this needs to be done at runtime, and every time a 
> function is called because PHP is dynamically typed, and not statically.
> 
> For example:
> 
>       myOverLoadedFunction(string $s, long $l, Weather $w)
> 
> could be:
> 
>       myOverLoadedFunction_s_l_cWeather
> 
> or something like that.
> 
> Doing these conversions would mean (in the most simple way), that for 
> each function call, a string needs to be manipulated to create the 
> mangled function name to lookup for in a hash, where right now, they 
> only have to be strtolower()'ed (because of case insensivity).
> 
> And then you need to do something sensible when *no* types have been 
> defined.

And we would run into similar issues as with the union types with regard
to weak typing.

-- 
Christoph M. Becker


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

Reply via email to