Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67280 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 57390 invoked from network); 2 May 2013 23:51:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 May 2013 23:51:42 -0000 Authentication-Results: pb1.pair.com smtp.mail=igor@wiedler.ch; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=igor@wiedler.ch; sender-id=unknown Received-SPF: error (pb1.pair.com: domain wiedler.ch from 217.26.49.183 cause and error) X-PHP-List-Original-Sender: igor@wiedler.ch X-Host-Fingerprint: 217.26.49.183 mxout004.mail.hostpoint.ch Received: from [217.26.49.183] ([217.26.49.183:50222] helo=mxout004.mail.hostpoint.ch) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2F/73-37535-C0CF2815 for ; Thu, 02 May 2013 19:51:41 -0400 Received: from [10.0.2.20] (helo=asmtp002.mail.hostpoint.ch) by mxout004.mail.hostpoint.ch with esmtp (Exim 4.72 (FreeBSD)) (envelope-from ) id 1UY3Hl-000EVQ-Ep; Fri, 03 May 2013 01:51:37 +0200 Received: from [84.73.218.139] (helo=[10.0.1.96]) by asmtp002.mail.hostpoint.ch with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.72 (FreeBSD)) (envelope-from ) id 1UY3Hl-000C3K-Be; Fri, 03 May 2013 01:51:37 +0200 X-Authenticated-Sender-Id: igor@wiedler.ch Content-Type: text/plain; charset=iso-8859-1 Mime-Version: 1.0 (Mac OS X Mail 6.3 \(1503\)) In-Reply-To: Date: Fri, 3 May 2013 01:51:36 +0200 Cc: "internals@lists.php.net" Content-Transfer-Encoding: quoted-printable Message-ID: References: <94D5D345-4D14-4BFF-9650-15E80205A6DE@wiedler.ch> <4A468FA3-3260-463C-9D4E-FA78736447C1@wiedler.ch> To: Sebastian Krebs X-Mailer: Apple Mail (2.1503) Subject: Re: [PHP-DEV] Re: Importing namespaced functions From: igor@wiedler.ch (Igor Wiedler) Your solution is flawed, it would not allow autoloading a function that = has the same (namespaced) name as a builtin. Example: // autoloadable function namespace foo { // make arg order consistent function array_filter($callback, $input) { return \array_filter($input, $callback); } function is_positive($x) { return $x > 0; } } namespace foo { var_dump(array_filter('foo\is_positive', [-2, -1, 0, 1, 2])); } Always triggering the autoloader is not feasible either, as it will lead = to tons of stat calls, one per namespace that any global function is called in. Potential solutions: Only autoload fully qualified or imported = functions. But there is lots of potential for bikeshedding there, plus it requires = more implementation effort, and quite possibly more performance and cache related = considerations that I am not aware of. As much as I would like to see function autoloading, I don't think = bundling the proposals is going to be beneficial. Which is why I'd rather just focus on one = issue at a time. Regards, Igor On May 3, 2013, at 12:18 AM, Sebastian Krebs = wrote: > Well, it is not as complex as it sounds >=20 > This is the behaviour right now >=20 > - Does X exists as namespaced function (current namespace or = imported)? > - Does X exists as global (builtin) function? > - Trigger error >=20 > The behaviour including autoloading would be more like >=20 > - Does X exists as namespaced function (current namespace or = imported)? > - Does X exists as global (builtin) function? > - Trigger autoload > - Does X exists as namespaced function (current namespace or imported) = now? > - Maybe: Does X exists as global function now? > - Trigger error >=20 > The autoloading itself could use parts already used for = class-autoloading. >=20 > // Signature > // spl_autoload_register($callback[, $type =3D AUTOLOAD_CLASS]); >=20 > $autoload =3D function ($name, $type =3D AUTOLOAD_CLASS) { > // Do something > }; > spl_autoload_register($autoload, AUTOLOAD_CLASS | = AUTOLOAD_FUNCTION | AUTOLOAD_CONSTANT); // "constant" here just to make = it complete >=20 > Namespaced functions without autoloading seems kindof incomplete, = especially because it isn't such a big deal to simply use the prefixed = one, so the benefit seems quite small to me :X >=20 > use MyFoo\Bar\MathFunctions as math; > $x =3D math\sin($y); >=20 >=20 > Just saying :) >=20 >=20 > Regards, > Sebastian >=20 >=20 >=20 > =20 >=20 > On May 2, 2013, at 11:40 PM, Sebastian Krebs = wrote: >=20 > > Hi, > > > > Are you going to cover autoloading of functions too? > > > > Regards, > > Sebastian >=20 >=20 >=20 > --=20 > github.com/KingCrunch=20