Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79405 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 89749 invoked from network); 3 Dec 2014 23:21:59 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Dec 2014 23:21:59 -0000 Authentication-Results: pb1.pair.com smtp.mail=rasmus@lerdorf.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rasmus@lerdorf.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain lerdorf.com designates 209.85.216.43 as permitted sender) X-PHP-List-Original-Sender: rasmus@lerdorf.com X-Host-Fingerprint: 209.85.216.43 mail-qa0-f43.google.com Received: from [209.85.216.43] ([209.85.216.43:41034] helo=mail-qa0-f43.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 25/29-15597-61B9F745 for ; Wed, 03 Dec 2014 18:21:59 -0500 Received: by mail-qa0-f43.google.com with SMTP id bm13so11082161qab.16 for ; Wed, 03 Dec 2014 15:21:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :subject:references:in-reply-to:content-type; bh=POpRsyWvzGQfd99pUNIFJVSTdg87ctvYBn+UglsgUk8=; b=UV2mRtIrydGeJXNG5y2ASjNI5y+8ncgKHnfFcOkLvy+nvik40iyL9onmHOb8Za6++U UihKGEL6P+j0PAi8skCfyKrueczDt06Io86oWfj/IIxdsXzeK01PUj2/k1rL3Pq70Ize kms23WeD0fSQ4mrRptum+6JDd5/RedWAmyL0y4TsnmHcj26ChMkd/WxYqZKXpy190JeX NDtEyJ3YTJrIHJ8+M4KqdGSgmwHgZjNiqenisE800o8ghS5w0WcyAwZKXfwWgoyk6mRr BDauRSAj5yReuAX0Gkdl12qurIq1LWQm5KUNpBhXC6kq/Vmk42FpX2DfSApkBx4U+uHw WEsg== X-Gm-Message-State: ALoCoQkjKPUhBRu8H1sINzQTkNTvLcK5YBn30W6uYgWngjKDnZ/fnwWJvvRKZ3KOqKwCYepNLqmI X-Received: by 10.224.79.212 with SMTP id q20mr12335769qak.4.1417648915678; Wed, 03 Dec 2014 15:21:55 -0800 (PST) Received: from [192.168.200.14] (c-50-131-44-225.hsd1.ca.comcast.net. [50.131.44.225]) by mx.google.com with ESMTPSA id z9sm24916164qai.19.2014.12.03.15.21.54 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Dec 2014 15:21:55 -0800 (PST) Message-ID: <547F9B11.3070207@lerdorf.com> Date: Wed, 03 Dec 2014 15:21:53 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: Robert Stoll , 'internals' References: <001201d00f41$cb284810$6178d830$@tutteli.ch> In-Reply-To: <001201d00f41$cb284810$6178d830$@tutteli.ch> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="BvjFDHGBtWXxCtaUH0hB1UancMlnvF8Tl" Subject: Re: [PHP-DEV] function overloading From: rasmus@lerdorf.com (Rasmus Lerdorf) --BvjFDHGBtWXxCtaUH0hB1UancMlnvF8Tl Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable On 12/03/2014 01:40 PM, Robert Stoll wrote: > Heya,=20 >=20 > =20 >=20 > I would like to know If it is somehow possible to overload existing fun= ctions by extensions. And if it is possible, are > there already some extension doing it? >=20 > I am not talking about the magic __call function. I am talking about so= mething 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= overloading functions is possible as well. Yes, it is possible and you can see an example in /ext/mbstring's RINIT function. It just loops through and replaces the entries in the function table. No real magic there. Note though that this is pretty ugly and since it is in the RINIT it means it will happen on every single request regardless of whether any of these functions are called during the request. As a quick local hack you can do it though. -Rasmus --BvjFDHGBtWXxCtaUH0hB1UancMlnvF8Tl Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iEYEARECAAYFAlR/mxEACgkQlxayKTuqOuANKACeOphQ3DgjSHt61Rd95RlnrZfC XscAn1woFuQWZvDVDEwwkx/xpfDD6sEG =HwBi -----END PGP SIGNATURE----- --BvjFDHGBtWXxCtaUH0hB1UancMlnvF8Tl--