Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:42755 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 96484 invoked from network); 21 Jan 2009 20:20:02 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Jan 2009 20:20:02 -0000 Authentication-Results: pb1.pair.com smtp.mail=greg@chiaraquartet.net; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=greg@chiaraquartet.net; sender-id=unknown Received-SPF: error (pb1.pair.com: domain chiaraquartet.net from 74.125.44.29 cause and error) X-PHP-List-Original-Sender: greg@chiaraquartet.net X-Host-Fingerprint: 74.125.44.29 yx-out-2324.google.com Received: from [74.125.44.29] ([74.125.44.29:18669] helo=yx-out-2324.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 17/C5-19181-07387794 for ; Wed, 21 Jan 2009 15:20:01 -0500 Received: by yx-out-2324.google.com with SMTP id 3so1574814yxj.83 for ; Wed, 21 Jan 2009 12:19:58 -0800 (PST) Received: by 10.65.11.17 with SMTP id o17mr244800qbi.4.1232569198046; Wed, 21 Jan 2009 12:19:58 -0800 (PST) Received: from pcp041215pcs.unl.edu (pcp041215pcs.unl.edu [129.93.124.154]) by mx.google.com with ESMTPS id p30sm4922277qbp.37.2009.01.21.12.19.55 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 21 Jan 2009 12:19:57 -0800 (PST) Message-ID: <49778369.4070709@chiaraquartet.net> Date: Wed, 21 Jan 2009 14:19:53 -0600 User-Agent: Thunderbird 2.0.0.6 (Macintosh/20070807) MIME-Version: 1.0 To: PHP Developers Mailing List X-Enigmail-Version: 0.95.7 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: [RFC lite] implement import of functions in namespace From: greg@chiaraquartet.net (Greg Beaver) This is a "testing of the waters" RFC. If there is interest, it will be followed with a patch. It should be noted that the patch for this has been available through the various vortexes of namespace syntax for over a year now, and it is an extremely simple patch. [RFC] Implement importing of functions to complement importing of classes and namespaces. example: [Problems this solves/Use cases] (1) Readability: * can make code more readable, much like importing classes/namespaces, by shortening line lengths and simplifying complex compound expressions (2) Backwards/Forwards compatibility * Occasionally, an internal function is extended with additional parameters. With function import, this can be accomplished in old versions. Example (pretend parameter "encoding" is added to strlen() in PHP 6.0): = 6) { return \strlen($string, $encoding); // use internal implementation } // now for the simulated parameter switch ($encoding) { ... } } } use function Util\strlen; // now code following will work in all PHP versions, and is forward-compatible to PHP 6 ?> [Proposed syntax changes] Function import is accomplished with the keyword "function" (T_FUNCTION token) as in T_USE T_FUNCTION [use_statement] use_statement can be any of \func or nsname\func or \nsname\func Samples: Just like the regular implementation of use for classes/namespaces: will raise a warning that this has no effect (import in global scope of unqualified name is meaningless). will act like: [Drawbacks] 1) requires changing the engine near beta 2) adds new syntax to namespaces [Non-issues/Slight issues] 1) would introduce one hash lookup on unqualified function calls at compile-time if any "use" statement exists in the script, which is unlikely to be detectable as a performance difference for even the largest scripts. Thanks, Greg