Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79403 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 84126 invoked from network); 3 Dec 2014 21:55:44 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Dec 2014 21:55:44 -0000 Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 192.64.116.216 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 192.64.116.216 imap10-3.ox.privateemail.com Received: from [192.64.116.216] ([192.64.116.216:39061] helo=imap10-3.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E1/68-15597-ED68F745 for ; Wed, 03 Dec 2014 16:55:43 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id CD5B12400C3; Wed, 3 Dec 2014 16:55:39 -0500 (EST) X-Virus-Scanned: Debian amavisd-new at imap10.ox.privateemail.com Received: from mail.privateemail.com ([127.0.0.1]) by localhost (imap10.ox.privateemail.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id vu6cAwhmJaMp; Wed, 3 Dec 2014 16:55:39 -0500 (EST) Received: from [10.129.234.52] (dab-yat1-h-1-8.dab.02.net [82.132.214.244]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.privateemail.com (Postfix) with ESMTPSA id 166B92400C2; Wed, 3 Dec 2014 16:55:38 -0500 (EST) References: <001201d00f41$cb284810$6178d830$@tutteli.ch> Mime-Version: 1.0 (1.0) In-Reply-To: <001201d00f41$cb284810$6178d830$@tutteli.ch> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Message-ID: <958E6385-B585-47DA-A305-11D2D1CF8F6B@ajf.me> Cc: internals X-Mailer: iPhone Mail (12B435) Date: Wed, 3 Dec 2014 21:55:28 +0000 To: Robert Stoll Subject: Re: [PHP-DEV] function overloading From: ajf@ajf.me (Andrea Faulds) Hi! > On 3 Dec 2014, at 21:40, Robert Stoll wrote: >=20 > Heya,=20 >=20 >=20 >=20 > I would like to know If it is somehow possible to overload existing functi= ons by extensions. And if it is possible, are > there already some extension doing it? Possibly in an extension, maybe. But as a weakly-typed, dynamic, reflective l= anguage, overloading of functions is both a bad idea (unpredictable program e= xecution) and unnecessary (types can be checked at runtime, optional paramet= ers exist). I also don't think overloading of functions is a good idea gener= ally, it leads to horrible APIs where there are 28 different versions of a f= unction each taking differently-typed arguments in different orders. I am gl= ad PHP largely lacks this madness, it makes it an easier language to read an= d to write. Overloading isn't needed: use optional parameters, a named optio= ns associative array, or check argument types within the function. If what y= ou're doing doesn't fit into those categories, maybe you need to make a sepa= rate function. > I am not talking about the magic __call function. I am talking about somet= hing like: let's assume GMP has overloaded the > function "abs" and therefore one can write: > $n =3D gmp_init(-12345678901234567890); > abs($n+ 2); // instead of using gmp_abs >=20 >=20 >=20 > I know that GMP has overloaded operators so it doesn't seem so far that ov= erloading functions is possible as well. Being able to change APIs provided by other libraries from your library soun= ds like a bad idea. If you just want abs() to work on bignums, my Big Integer Support RFC would h= andle that. :) -- Andrea Faulds http://ajf.me/=