Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:40569 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 67577 invoked from network); 20 Sep 2008 03:59:53 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Sep 2008 03:59:53 -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 208.83.222.18 cause and error) X-PHP-List-Original-Sender: greg@chiaraquartet.net X-Host-Fingerprint: 208.83.222.18 unknown Linux 2.6 Received: from [208.83.222.18] ([208.83.222.18:46976] helo=mail.bluga.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 47/20-65213-73574D84 for ; Fri, 19 Sep 2008 23:59:52 -0400 Received: from mail.bluga.net (localhost.localdomain [127.0.0.1]) by mail.bluga.net (Postfix) with ESMTP id 7C14AC0F395 for ; Fri, 19 Sep 2008 20:58:52 -0700 (MST) Received: from [192.168.223.130] (unknown [76.84.4.101]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.bluga.net (Postfix) with ESMTP id 1F916C0F38F for ; Fri, 19 Sep 2008 20:58:52 -0700 (MST) Message-ID: <48D47532.8080102@chiaraquartet.net> Date: Fri, 19 Sep 2008 22:59:46 -0500 User-Agent: Thunderbird 2.0.0.16 (X11/20080724) MIME-Version: 1.0 To: internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: ClamAV using ClamSMTP Subject: solving the namespace conflict issues between function/static method class constant/ns constant From: greg@chiaraquartet.net (Greg Beaver) Hi all, There is a problem in the namespace implementation. This code demonstrates the issue: code.inc: main.php: There are 5 ways to solve this: 1) document it and hope no one uses it [this is the current strategy, minus the documentation part] 2) add a fatal error on conflicting names. http://pear.php.net/~greg/ns_method.func.conflict.patch.txt Unfortunately, this can only work for methods/functions, as namespace constants are actually defined at run-time, and so conflicts can't be detected until then, which does not provide any benefit (you want to catch this conflict at compile-time). 3) create a disambiguation method. http://pear.php.net/~greg/ns.func_const.patch.txt This introduces function:: and const:: as prefixes to disambiguate. The drawback of this approach is that "foo::test::bar" will always look for class "foo::test", which means if autoload is defined, it will be called for all non-prefixed function calls. Unfortunately, the only other keyword for disambiguating would be "class::" as in "class::foo::test::bar()" but this is excessively confusing. 4) remove functions/constants from namespaces 5) a simply syntax change to namespaces, introducing a new concept: namespace element. A namespace element is a class, function or constant defined within a namespace declaration: This is similar to class elements: Currently, this code: creates a class named "foo::bar::buh", essentially joining the namespace "foo::bar" and its class element "buh" with the separator "::". This turns out to be the root of the problem with the conflicts between class elements and namespace elements. The last patch introduces a new namespace element operator to delineate the boundary between namespace name and element name. For the patch, I recycled T_OBJECT_OPERATOR (->). current way: test(); // namespace foo::bar, call to function element test() foo->bar::test(); // namespace foo, call to static method element test() in class element bar foo->myconst; // namespace foo constant myconst foo::myconst; // class foo constant myconst ?> The patch is at: http://pear.php.net/~greg/ns.element.patch.txt This is the most extensive change. The patch preserves :: as global element accessor (::strlen() calls strlen internal function, for instance). I'm happy to answer any other questions. So, these are the choices. I suggest we all take a rational look at the options, and understand the consequences of each, and make the best choice possible. Thanks, Greg