Re: solving the namespace conflict issues betweenfunction/staticmethod class constant/ns constant

From: Date: Mon, 29 Sep 2008 04:29:23 +0000
Subject: Re: solving the namespace conflict issues betweenfunction/staticmethod class constant/ns constant
References: 1 2 3 4 5 6 7 8 9 10 11 12  Groups: php.internals 
Request: Send a blank email to internals+get-40752@lists.php.net to get a copy of this message
Hi, The second highest vote was :::, but there was strong objection to this as well from some. The problem, I still believe, is that we are focused on having the same:::stupid:::operator:::between:::everything. The truth is that in source files, there is a clear boundary between namespace definition as in: <?php namespace foo::bar; ?> and the things in the namespace, as in: <?php class bar {} ?>
Or how about :::: :)? Although I'm not a fan of the backslash, I think it's starting to look better and better on the background of all discussed so far. Here are reasons and examples: 1) It's one char, it's easy to type, it's visually distinct from -> and ::, for both the parser and humans alike. 2) We need to use [separatator][identifier] to refer to global classes and possibly functions, from a namespace, and \Foo() is a lot more intuitive than ::Foo() in this setup, because a backslash evokes the same semantics we use with relative and absolute filepaths. 3) We'll have the chance of properly introducing namespaces that really wall off libraries with all their identifiers, including variables, constants, functions and classes, the way it's supposed to work (and I'm also one of the people who'd like to be able to namespace my function-only libraries too). 4) Examples of how this sits visually and works in practice (each line is a separate example). Notice we use the exact same semantics as in filepaths (with the addition of "use" aliases), which is intuitive and constistent for both the implementers and the users of this feature: namespace Foo\Bar\Baz; use \globalFunc(); globalFunc(); // aliased global function namespace Abc; \globalFunc(); // direct use without alias globalFunc(); // no need for prefix in global space use \GlobalClass; GlobalClass::method(); $\globalVar; $localVar; $\Foo\Far\namespacedVar; \Foo\Bar\NamespacedClass::method(); // absolute identifier namespace Foo; Bar\NamespacedClass::method(); // relative reference to the same class; use Foo\Bar; Bar\NamespacedClass::method(); // aliased reference to the same class \Foo\Bar\NamespacedFunc(); // absolute namespace path namespace Foo; Bar\NamespacedFunc(); // relative reference to the same function use \Foo\Bar; Bar\NamespacedFunc(); // aliased reference to the same function Regards, SV

« previous php.internals (#40752) next »