Well I had given some thought to that :)

Instead of using mangled names and calculating the canonical name at
runtime, keep the name, but convert the function hashtable from a table of
op arrays into a table linked lists, of op arrays.

A non-overloaded function would be the only element in its list, so there
would be no need to process the entire signature, preserving the
performance of the current system.

In the event of an overloaded function, yes, there would be a performance
hit, but only if overloading is used.  And it should still be faster than
emulating overloading in PHP.

Lastly, a linked list allows on the fly additions and reordering when
organising the overloads by restrictiveness in descending order.
On 6 Jun 2016 11:03 a.m., "Derick Rethans" <der...@php.net> 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.

cheers,
Derick

Reply via email to