Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91436 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 91180 invoked from network); 26 Feb 2016 14:10:21 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Feb 2016 14:10:21 -0000 Authentication-Results: pb1.pair.com header.from=johannes@schlueters.de; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=johannes@schlueters.de; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain schlueters.de from 217.114.215.10 cause and error) X-PHP-List-Original-Sender: johannes@schlueters.de X-Host-Fingerprint: 217.114.215.10 mail.experimentalworks.net Received: from [217.114.215.10] ([217.114.215.10:37163] helo=mail.experimentalworks.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 54/24-55238-BCC50D65 for ; Fri, 26 Feb 2016 09:10:20 -0500 Received: by mail.experimentalworks.net (Postfix, from userid 1003) id A59E64202F; Fri, 26 Feb 2016 15:10:27 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on km31408.keymachine.de X-Spam-Level: X-Spam-Status: No, score=-1.0 required=4.0 tests=ALL_TRUSTED autolearn=unavailable autolearn_force=no version=3.4.0 X-Spam-HAM-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP Received: from [192.168.2.34] (ppp-93-104-12-37.dynamic.mnet-online.de [93.104.12.37]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: johannes@schlueters.de) by mail.experimentalworks.net (Postfix) with ESMTPSA id E95E64202B; Fri, 26 Feb 2016 15:10:25 +0100 (CET) Message-ID: <1456495810.5232.17.camel@kuechenschabe> To: Andrea Faulds Cc: internals@lists.php.net Date: Fri, 26 Feb 2016 15:10:10 +0100 In-Reply-To: References: Content-Type: multipart/signed; micalg="pgp-sha1"; protocol="application/pgp-signature"; boundary="=-dczmh2v/HlQXCcrTd+gR" X-Mailer: Evolution 3.10.4-0ubuntu2 Mime-Version: 1.0 Subject: Re: [PHP-DEV] [RFC] Callable constructors From: johannes@schlueters.de (Johannes =?ISO-8859-1?Q?Schl=FCter?=) --=-dczmh2v/HlQXCcrTd+gR Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, 2016-02-26 at 11:30 +0000, Andrea Faulds wrote: > This is true for a trivial implementation like the one above, but I=20 > would point out that a more sophisticated userland implementation could= =20 > fix this by generating PHP code. You don't have to generate PHP code for this to work: $arr =3D is_string($func) ? explode("::", $func, 2) : $func; $ref =3D (sizeof($arr) =3D=3D=3D 2) ? new ReflectionMethod($arr[0], $arr[1]) : new ReflectionFunction($func); $args =3D identifyArgumentsAndGetCtorArgs($ref); if (sizeof($arr) =3D=3D=3D 2 && $arr[1] =3D=3D=3D '__construct') { $rc =3D new ReflectionClass($arr[0]); return $rc->newInstanceArgs($args); } else { return $ref->invokeArgs($args); } I haven't tested this and it might need some fine tuning, but isn't really complicated. (Of course you can generate PHP code for this trivially in order to avoid the small reflection overhead) > So it's still worth questioning whether this needs to be a built-in=20 > function. I think it is quite obscure and a hardly used feature. Language features and syntax sugar things should be common things. johannes --=-dczmh2v/HlQXCcrTd+gR Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iQEcBAABAgAGBQJW0FzDAAoJEH3sTmn8nIPXYbMIALWfWyIzW91nRC0WvuSuJNr/ gWn/Z4ZjcpWvOEC1qUKUQJcMATR4bddPHKg1WZIhw8CeBdAcwFsOTyyeqtaVsNXb 4Fk+MGbbVisx4xivmw2eE/w74Y7peZUMbam7KYNAj2ZABiIbiy0uuGc/mcPUK9FO Y8/OqxHeScThe6aj6N7YlLFOKU33lnC/wtm7TvYlRXJYX/dCKbaX79kAcMWv/N2+ y59KVxL7qcu+bxBXv/MCxqgGLJ3buLJzuiBpUIfC4R63k79GFDgD7ZR5tM8tMkLi Az+qihVA1COLI6/pkBTXjcR39eTc/7LHKwPJC9yjoCHVDf2PNAGUkTNa/TInKgg= =nMXp -----END PGP SIGNATURE----- --=-dczmh2v/HlQXCcrTd+gR--