Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93833 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 66268 invoked from network); 6 Jun 2016 10:04:02 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Jun 2016 10:04:02 -0000 Authentication-Results: pb1.pair.com header.from=derick@php.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=derick@php.net; spf=unknown; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain php.net does not designate 82.113.146.227 as permitted sender) X-PHP-List-Original-Sender: derick@php.net X-Host-Fingerprint: 82.113.146.227 xdebug.org Received: from [82.113.146.227] ([82.113.146.227:52258] helo=xdebug.org) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 88/A0-60933-19A45575 for ; Mon, 06 Jun 2016 06:04:02 -0400 Received: from localhost (localhost [IPv6:::1]) by xdebug.org (Postfix) with ESMTPS id 635CC10C01C; Mon, 6 Jun 2016 11:03:58 +0100 (BST) Date: Mon, 6 Jun 2016 11:03:58 +0100 (BST) X-X-Sender: derick@whisky.home.derickrethans.nl To: Dominic Grostate cc: PHP internals In-Reply-To: Message-ID: References: User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Subject: Re: [PHP-DEV] Opinion on function/method name overloading From: derick@php.net (Derick Rethans) 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