Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:40589 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 96852 invoked from network); 21 Sep 2008 03:36:40 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Sep 2008 03:36:40 -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:33072] helo=mail.bluga.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 75/58-65213-641C5D84 for ; Sat, 20 Sep 2008 23:36:39 -0400 Received: from mail.bluga.net (localhost.localdomain [127.0.0.1]) by mail.bluga.net (Postfix) with ESMTP id 5F61EC0E0B3; Sat, 20 Sep 2008 20:35:38 -0700 (MST) Received: from [192.168.0.106] (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 E83BBC0E031; Sat, 20 Sep 2008 20:35:37 -0700 (MST) Message-ID: <48D5C151.1070607@chiaraquartet.net> Date: Sat, 20 Sep 2008 22:36:49 -0500 User-Agent: Thunderbird 2.0.0.16 (X11/20080724) MIME-Version: 1.0 To: Larry Garfield CC: internals@lists.php.net References: <48D47532.8080102@chiaraquartet.net> <10845a340809201643q59e27211i471e09241f7253b1@mail.gmail.com> <200809202000.38870.larry@garfieldtech.com> In-Reply-To: <200809202000.38870.larry@garfieldtech.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Virus-Scanned: ClamAV using ClamSMTP Subject: Re: [PHP-DEV] solving the namespace conflict issues between function/static method class constant/ns constant From: greg@chiaraquartet.net (Gregory Beaver) Larry Garfield wrote: > On Saturday 20 September 2008 6:43:41 pm Richard Quadling wrote: > >>>> 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: >>>> >>>> >>> namespace foo; >>>> class bar {} // class element bar in namespace foo >>>> function bar(){} // function element bar in namespace foo >>>> const bar=1; // const element bar in namespace foo >>>> ?> >>>> >>>> This is similar to class elements: >>>> >>>> >>> class foo { >>>> function bar(){} // method element bar in class foo >>>> const bar=1; // constant element bar in class foo >>>> public $bar=1; // variable element bar in class foo >>>> } >>>> ?> >>>> >>>> Currently, this code: >>>> >>>> >>> namespace foo::bar; >>>> class buh{} >>>> ?> >>>> >>>> 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: >>>> >>> foo::bar->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. [snip] > I agree that #5 seems like the best solution. The problem is caused by the > double meaning of ::. All of the other solutions feel like bandaids. > > Of course, the problem then is finding a symbol that is not already used. I > don't think reusing -> is any wiser than reusing ::. # would be great if it Let's be clear. Here is a sample of code with the new syntax: is only used once // to specify the boundary between namespace name and namespace member. $a = new name::still::has::double::colon->blow; $a = new colon->blow; // static method call colon->blow::hard(); // or name::still::has::double::colon->blow::hard(); // ns constant echo colon->oscopy; namespace blow; function hard(){} namespace a::third::name; // demonstrate importing a class name // which is different from importing a namespace name use name::still::has::double::colon->blow; // class static method blow::hard(); // namespace function ::blow->hard(); // class constant echo blow::byblow; ?> Two important things to note: - ambiguity between namespace name and class name is eliminated - this separator is self-documenting. One does not need to grep source code to determine whether blah->thing is a namespaced function or a static method of class blah. The same is true of use statements. It is crystal clear whether we are importing a namespace or a class name. This will make debugging someone else's code a lot easier than it otherwise would be. Jochem has informed me he is taking care of the wiki RFC for this stuff. I am allergic to wikis, unfortunately. Thanks, Greg