Basic Namespace Requirements

php.internals

Jessie Hernandez

20 years ago
All, After seeing Dmitry's patch, all he is allowing inside a module are import statements and classes. So, the question is, can we scrap both namespace constants and namespace functions and just stay with classes (as was agreed on several months ago, Andi himself agreeing to it)? This would make the patch smaller, simpler, AND would allow me to reuse the "::" operator (and there would be no conflicts with ternary operations). I think this is the best solution thus far. If any one of you still feels a need for constants/functions, PLEASE show me a _valid_ example that cannot be accomplished by just simply putting the constant/function inside a class in the namespace. If I don't hear of any valid arguments, then I'm going to go ahead and scrap constants and functions and then concentrate on the final details of the patch. Regards, Jessie Hernandez

Sara Golemon

20 years ago
> So, the question is, can we scrap both namespace constants and namespace > functions and just stay with classes (as was agreed on several months ago, > Andi himself agreeing to it)? This would make the patch smaller, simpler, > AND would allow me to reuse the "::" operator (and there would be no > conflicts with ternary operations). >
Absolutely. Static methods and Class constants are more than sufficient. All the added functionality of namespaces without all the baggage. +1 -Sara

Jason Garber

20 years ago
Hello Sara, Please explain what the difference is between nested classes, and this type of namespacing? If you scrapped namespace constants and functions, then all we have left is classes. If it was looked at as nested classes, then we get all the functionality with all the simplicity and the benefit of being able to use "::". Please take a moment to explain, because I am an avid user, not a tokenizer :)
-- Best regards, Jason mailto:jason@ionzoft.com Monday, November 28, 2005, 5:25:41 PM, you wrote: >> So, the question is, can we scrap both namespace constants and namespace >> functions and just stay with classes (as was agreed on several months ago, >> Andi himself agreeing to it)? This would make the patch smaller, simpler, >> AND would allow me to reuse the "::" operator (and there would be no >> conflicts with ternary operations). >> SG> Absolutely. Static methods and Class constants are more than sufficient. SG> All the added functionality of namespaces without all the baggage. SG> +1 SG> -Sara

Sebastian Bergmann

20 years ago
Sara Golemon schrieb:
> All the added functionality of namespaces without all the baggage.
+1
-- Sebastian Bergmann http://www.sebastian-bergmann.de/ GnuPG Key: 0xB85B5D69 / 27A7 2B14 09E4 98CD 6277 0E5B 6867 C514 B85B 5D69

Marcus Börger

20 years ago
Hello Jessie, i already showed that dropping constants in namespaces leeds to static classes or private classes. So we are just shifting here. Instead of doing work that is worth nothing you should simply try to come up with a working patch using a working separator which can clearly only be "\". best regards marcus Monday, November 28, 2005, 11:04:43 PM, you wrote:
> All,
> After seeing Dmitry's patch, all he is allowing inside a module are import > statements and classes.
> So, the question is, can we scrap both namespace constants and namespace > functions and just stay with classes (as was agreed on several months ago, > Andi himself agreeing to it)? This would make the patch smaller, simpler, > AND would allow me to reuse the "::" operator (and there would be no > conflicts with ternary operations).
> I think this is the best solution thus far. If any one of you still feels a > need for constants/functions, PLEASE show me a _valid_ example that cannot > be accomplished by just simply putting the constant/function inside a class > in the namespace.
> If I don't hear of any valid arguments, then I'm going to go ahead and scrap > constants and functions and then concentrate on the final details of the > patch.
> Regards,
> Jessie Hernandez
Best regards, Marcus

Stanislav Malyshev

20 years ago
MB>>work that is worth nothing you should simply try to come up with a working MB>>patch using a working separator which can clearly only be "\". That's one creative way of using "working", "clearly" and "only" with meanings that I was not familiar with before. :)
-- Stanislav Malyshev, Zend Products Engineer stas@zend.com http://www.zend.com/ +972-3-6139665 ext.115

Timm Friebe

20 years ago
Hi,
> Hello Jessie,
[...]
> you should simply try to come up with a working > patch using a working separator which can clearly > only be "\".
Why is \ the only character that could work? Because it's unused? What about for examole the tilde (~) or the exclamation mark (!)? - both of them are prefixes only, so neither a!b nor a~b will conflict. On the backslash: It'll be a bitch in places where you need the class name as a string (reflection) because \ needs to be escaped withing a string. Think: How many backslashes do you need in a regular expression using double quotes to represent a single backslash (try to answer this question without trying it out. Was it two? Three? four? Six?) - Timm

Marcus Börger

20 years ago
Hello Timm, Sunday, December 4, 2005, 3:22:48 PM, you wrote:
> Hi, > >> Hello Jessie, > [...] >> you should simply try to come up with a working >> patch using a working separator which can clearly >> only be "\".
> Why is \ the only character that could work? Because it's unused? What about > for examole the tilde (~) or the exclamation mark (!)? - both of them are > prefixes only, so neither a!b nor a~b will conflict.
Right, but doesn't make the code readable since once again you give operators multiple meanings. And we don't want to become another perl, do we?
> On the backslash: It'll be a bitch in places where you need the class name > as a string (reflection) because \ needs to be escaped withing a string. > Think: How many backslashes do you need in a regular expression using double > quotes to represent a single backslash (try to answer this question without > trying it out. Was it two? Three? four? Six?)
Wrong assumption. The \ won't need to be escaped. Best regards, Marcus

Wez Furlong

20 years ago
On 12/4/05, Marcus Boerger <helly@php.net> wrote:
> > On the backslash: It'll be a bitch in places where you need the class name > > as a string (reflection) because \ needs to be escaped withing a string. > > Think: How many backslashes do you need in a regular expression using double > > quotes to represent a single backslash (try to answer this question without > > trying it out. Was it two? Three? four? Six?) > > Wrong assumption. The \ won't need to be escaped.
Err, what about "my\namespace" ? --Wez.

Marcus Börger

20 years ago
Hello Wez, Sunday, December 4, 2005, 7:36:19 PM, you wrote:
> On 12/4/05, Marcus Boerger <helly@php.net> wrote: >> > On the backslash: It'll be a bitch in places where you need the class name >> > as a string (reflection) because \ needs to be escaped withing a string. >> > Think: How many backslashes do you need in a regular expression using double >> > quotes to represent a single backslash (try to answer this question without >> > trying it out. Was it two? Three? four? Six?) >> >> Wrong assumption. The \ won't need to be escaped.
> Err, what about "my\namespace" ?
That would be the string "my" <newline> "namespace". As a classname it would be "class namespace in namespace my". I guess your point is how to use that in ""-$-expressions, right? $bla = "${foo\bar::constant}"; Best regards, Marcus

Wez Furlong

20 years ago
On 12/4/05, Marcus Boerger <helly@php.net> wrote:
> >> Wrong assumption. The \ won't need to be escaped. > > Err, what about "my\namespace" ? > > That would be the string "my" <newline> "namespace".
Exactly.
> As a classname it would be "class namespace in namespace my". > I guess your point is how to use that in ""-$-expressions, right? > $bla = "${foo\bar::constant}";
Thus it does need to be escaped when used in double-quoted strings. --Wez.

Marcus Börger

20 years ago
Hello Wez, Sunday, December 4, 2005, 7:45:14 PM, you wrote:
> On 12/4/05, Marcus Boerger <helly@php.net> wrote: >> >> Wrong assumption. The \ won't need to be escaped. >> > Err, what about "my\namespace" ? >> >> That would be the string "my" <newline> "namespace".
> Exactly.
>> As a classname it would be "class namespace in namespace my". >> I guess your point is how to use that in ""-$-expressions, right? >> $bla = "${foo\bar::constant}";
> Thus it does need to be escaped when used in double-quoted strings.
No, it uses the same parser inside ${...} or $[a-zA-Z_][a-zA-Z_0-9...]+ as it does for other stuff too. So no no escaping is needed. Best regards, Marcus

Wez Furlong

20 years ago
You're ignoring the case where people use "my\namespace" as a string to pass into eg: the reflection API, call_user_function etc. etc. --Wez. On 12/4/05, Marcus Boerger <helly@php.net> wrote:

Oliver Grätz

20 years ago
Marcus Boerger schrieb:
> $bla = "${foo\bar::constant}";
This is WORSE than Perl. OLLi

Marcus Börger

20 years ago
Hello Oliver, unfortunatley it is (besides the namespaces) already leagal syntax. marcus Sunday, December 4, 2005, 11:59:14 PM, you wrote:
> Marcus Boerger schrieb: >> $bla = "${foo\bar::constant}";
> This is WORSE than Perl.
> OLLi
Best regards, Marcus

Oliver Grätz

20 years ago
Jessie Hernandez schrieb:
> I think this is the best solution thus far. If any one of you still feels a > need for constants/functions, PLEASE show me a _valid_ example that cannot > be accomplished by just simply putting the constant/function inside a class > in the namespace.
No complaints from me. I try to avoid both since a long time. Functions would be nice, simply for convenience (sometimes one wants to use something so often that a static method just isn't as nice), but I really don't see any need for global constants EXCEPT that supporting everything that's currently OUTSIDE of namespaces would allow to completetly clean it without further work.
> If I don't hear of any valid arguments, then I'm going to go ahead and scrap > constants and functions and then concentrate on the final details of the > patch.
Did you give the "no namespaces in the ternary" idea a try? Even if this doesn't make it I'd be happy to know if it works. Anyways, +2 for both : and :: OLLi PS: I'm now preparing the final table. We should not stretch this any more ;-) The First subscribers are getting heart attcks from too much mail...

Bart de Boer

20 years ago
I personally never use constants anyway. But at least functions and variables should work with namespaces: namespace name1 { $var = 3; function func(); } From a language perspective those should exist only in that namespace. I also think '\' as a seporator is nice. It has this nice filesystem feeling to it. :) (Although now I'm wondering if we use '\' as a seporator, shouldn't it be possible to use '\' in stead of the Paamayim Nekudotayim '::' seporator as well? Just to keep things consistent? hmmm... ) Oliver Grätz wrote: