Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93835 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 70813 invoked from network); 6 Jun 2016 10:31:46 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Jun 2016 10:31:46 -0000 Authentication-Results: pb1.pair.com header.from=codekestrel@googlemail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=codekestrel@googlemail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain googlemail.com designates 74.125.82.49 as permitted sender) X-PHP-List-Original-Sender: codekestrel@googlemail.com X-Host-Fingerprint: 74.125.82.49 mail-wm0-f49.google.com Received: from [74.125.82.49] ([74.125.82.49:37658] helo=mail-wm0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2C/91-60933-11155575 for ; Mon, 06 Jun 2016 06:31:45 -0400 Received: by mail-wm0-f49.google.com with SMTP id k204so20692364wmk.0 for ; Mon, 06 Jun 2016 03:31:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=nK4yVNso2GEbCZ8Er2DMrpzv+/v6Kk64zPRA17nUa/I=; b=J7EeQKAIJ6iXtfUC+N7C4VAZb34wbcYwE8bv22gf+9tEmWSXkvL8Pyt39CVY/SX9a2 kwbj2+TlP8uG8v3u2VKL6BunCsjaYmVxHBZqVGgwRYhCEyd0+YGDVBmS6g7dEWbb+AGK AdydhGC81joO4HOgfnPmFAm7ghQi0/oO3YUk/BoDWR9K3uZpuSX+lMa1ZP0cMOI5PYl6 RQoV9Jhr4+rdpILEzWEeOjv0x0a8fBAUgZrXYuFW2M/hMRCDZ+ek09t5MB21dIZ2X3WW CV92QJW0t9qfx33K9SBuSW4vlOQuYVccbiCX5RJFnoQauUAt8E469UKfVHUCqJjtKVaW kH6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=nK4yVNso2GEbCZ8Er2DMrpzv+/v6Kk64zPRA17nUa/I=; b=i2Mi9bHrEOPZ9cx8zHILN0CNMh5lGQgZrk/X9PzFiMJ1V6xYOFSZzCQVcahfz79n1D IDbqZLtac/MgBPQBXjnQGVTBWHWxElQl6ko+wTXEmRLJBScgqTMfVbcoYnawlqB5l7fe m1BeMXSW3aOF/foTrbK11xeZcuiDCa1sOwnLGgTQRNga7sStK/0VGzaKx3Pr5iEAdqlJ Zcd5Vd0mTY6HlvkZmGy8QXusayWWIQvLry3v54c3JcrwGNVn8COPldvm0yCFwObI+Yml EFSE83/N2FyGab60qVEeq5aecw7lcs5ceLCjW9uXxrW+NmA8+s1ZEEWvxTdUOBrM+IwX sBEA== X-Gm-Message-State: ALyK8tKtSaX1BrjplGocvIIwkThoyzD6biQdJfnl0zH3lM1auA+samSYO/PKyzB7d7Oy/R7XpsbzfQipQGq7Yw== MIME-Version: 1.0 X-Received: by 10.194.94.165 with SMTP id dd5mr14934155wjb.31.1465209101885; Mon, 06 Jun 2016 03:31:41 -0700 (PDT) Received: by 10.28.130.2 with HTTP; Mon, 6 Jun 2016 03:31:41 -0700 (PDT) Received: by 10.28.130.2 with HTTP; Mon, 6 Jun 2016 03:31:41 -0700 (PDT) In-Reply-To: References: Date: Mon, 6 Jun 2016 11:31:41 +0100 Message-ID: To: Derick Rethans Cc: PHP internals Content-Type: multipart/alternative; boundary=047d7bb043460a26f505349994c0 Subject: Re: [PHP-DEV] Opinion on function/method name overloading From: codekestrel@googlemail.com (Dominic Grostate) --047d7bb043460a26f505349994c0 Content-Type: text/plain; charset=UTF-8 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" 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 --047d7bb043460a26f505349994c0--