Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:40574 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 48587 invoked from network); 20 Sep 2008 16:24:35 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Sep 2008 16:24:35 -0000 Authentication-Results: pb1.pair.com header.from=ekneuss@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=ekneuss@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.162.180 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: ekneuss@gmail.com X-Host-Fingerprint: 209.85.162.180 el-out-1112.google.com Received: from [209.85.162.180] ([209.85.162.180:60882] helo=el-out-1112.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CB/FB-65213-1C325D84 for ; Sat, 20 Sep 2008 12:24:34 -0400 Received: by el-out-1112.google.com with SMTP id o28so247700ele.2 for ; Sat, 20 Sep 2008 09:24:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:sender :to:subject:cc:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references :x-google-sender-auth; bh=eA0mI98gH7s5dh8YPH4JxsrHSHbpqTK+8OM0NC/+yW4=; b=c79Dht2OWme+eQ4rrZYgzNEd2ohMqRzMQ3eXrqiYKhZvV0OyXWzeoNXxNqtDUUW1c3 NqHQPc6JTgGfiE9UnTUu+Fv0+xNkwUDPOKjDti32xsrFFbdyDyzmYrOyGwZ1BeJPwvMK Ooq3jIZhjdLTalqGPSBrJvwyoN9PPh0UhUG5k= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references:x-google-sender-auth; b=sSLyhWa6NeaMLDbobCAMoQeHLENJ6rmx6sAdlvChcqq+pJ5blFVGlPYNHoDFG4HH3t G/MszzpH5TSrl3pc9xaBfHR95C59Q3ARbshuld9CgxAE1mpa6JFjmEfnLO9aZoU48MIx rSHZ21fvMJkTNe4/e8fuLleSOrAC9IlcASIow= Received: by 10.151.157.1 with SMTP id j1mr4710869ybo.211.1221927871127; Sat, 20 Sep 2008 09:24:31 -0700 (PDT) Received: by 10.150.225.7 with HTTP; Sat, 20 Sep 2008 09:24:31 -0700 (PDT) Message-ID: Date: Sat, 20 Sep 2008 18:24:31 +0200 Sender: ekneuss@gmail.com To: "Greg Beaver" Cc: internals@lists.php.net In-Reply-To: <48D47532.8080102@chiaraquartet.net> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <48D47532.8080102@chiaraquartet.net> X-Google-Sender-Auth: e6613f883e98aea7 Subject: Re: [PHP-DEV] solving the namespace conflict issues between function/static method class constant/ns constant From: colder@php.net ("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