Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:40583 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 4089 invoked from network); 20 Sep 2008 23:43:46 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Sep 2008 23:43:46 -0000 Authentication-Results: pb1.pair.com header.from=rquadling@googlemail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=rquadling@googlemail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain googlemail.com designates 209.85.128.186 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: rquadling@googlemail.com X-Host-Fingerprint: 209.85.128.186 fk-out-0910.google.com Received: from [209.85.128.186] ([209.85.128.186:42325] helo=fk-out-0910.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B3/65-65213-0BA85D84 for ; Sat, 20 Sep 2008 19:43:45 -0400 Received: by fk-out-0910.google.com with SMTP id 18so989328fks.7 for ; Sat, 20 Sep 2008 16:43:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:reply-to :to:subject:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=m/oHwhqrgEdSpI5fc02gL89r7JDgkjJrmPHBxwyVoFM=; b=AjZSR8N2p2xnQ3Rizv4CAi6MKCF12D/u5imNQiSIFK/lGo844lw3sKySt7jqT0jr+u Z8Ti6glWD/ejUxk78NbZgD97MdBsgSfdEcs0Sx9lJ3cL7a/aepnylbP+v+wO/VE41Spo ZrqK7TRLCz6WdCbKz5fLQ9S89ri2ZdYXvGtN0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=message-id:date:from:reply-to:to:subject:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=X6rtY9zVfEMYDIRazstJECXPSuxED+na2rDUaMteehizgdTWhfzIzlz68plzErt9kd pCd6uthBSn8wv5lqYAJiVsRTjm83Xy1rBrZ7IcIAy976suT8Jr+rSM2/Mxvf0k/qJjtZ 6qr0/QF58XlG5jsHxHK6tUKsoGzubfTMUH54A= Received: by 10.103.137.19 with SMTP id p19mr1438500mun.108.1221954221525; Sat, 20 Sep 2008 16:43:41 -0700 (PDT) Received: by 10.103.212.17 with HTTP; Sat, 20 Sep 2008 16:43:41 -0700 (PDT) Message-ID: <10845a340809201643q59e27211i471e09241f7253b1@mail.gmail.com> Date: Sun, 21 Sep 2008 00:43:41 +0100 Reply-To: RQuadling@GoogleMail.com To: "PHP Internals List" In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <48D47532.8080102@chiaraquartet.net> Subject: Re: [PHP-DEV] solving the namespace conflict issues between function/static method class constant/ns constant From: rquadling@googlemail.com ("Richard Quadling") 2008/9/20 Etienne Kneuss : > Hello, > > On Sat, Sep 20, 2008 at 5:59 AM, Greg Beaver wrote: >> Hi all, >> >> There is a problem in the namespace implementation. This code demonstrates >> the issue: >> >> code.inc: >> > namespace foo; >> class test { >> const my = 1; >> static function bar(){} >> } >> >> namespace foo::test; >> const my = 2; >> function bar(){} >> ?> >> >> main.php: >> > include 'code.inc'; >> foo::test::bar(); // always calls namespace function >> call_user_func(array('foo::test', 'bar')); // the only way to call static >> method >> echo foo::test::my; // always 2 >> $a = new foo::test; >> echo $a::my; // the only way to access foo::test::my >> ?> >> >> 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. >> >> > function::foo::test::bar(); // always calls namespace function >> foo::test::bar(); // always calls static method if defined, falls back to ns >> function if not >> const::foo::test::my; // namespace constant >> foo::test::my; // class constant >> ?> >> >> 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: >> >> > 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. >> >> 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 > > Good work, but I (and I'm probably not alone) can't really keep up > with all those namespace threads and proposals for changes and > resolution fixes and this and that,so : > > Please use our nice RFC system! > > Regards > > -- > Etienne Kneuss > http://www.colder.ch > > Men never do evil so completely and cheerfully as > when they do it from a religious conviction. > -- Pascal > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > How feasible would it be to use # as the namespace separator. I know # is used for comments, but with /* */ and // that all seems covered. namespace#function() vs class::static() Seems like a winner. Just a whole ton of BC though for those using # for comments. Regards, Richard. -- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!"