Hi Richard, "const" is usefull to declare "compile-time" constants in current scope (class or namespace). The syntax is the same. It is not allowed to use functions and variables in such declarations (this ability was proposed but then it was removed before commit).
define() is a runtime function that allows declaring constant at run-time. Of course this function defines constants in global scope. Thanks. Dmitry. > -----Original Message----- > From: Richard Lynch [mailto:[EMAIL PROTECTED] > Sent: Sunday, August 26, 2007 7:50 AM > To: Dmitry Stogov > Cc: 'PHP Internals List' > Subject: RE: [PHP-DEV] Constants in namesapces > > > On Wed, August 22, 2007 8:03 am, Dmitry Stogov wrote: > > You can have "const" outside namespaces but they are not real > > compile-time constants. > > They are set during execution in the same way as define() does. > > > > <?php > > const DIR = dirname(__FILE__); > > echo DIR; > > ?> > > You do realize this is going to engender a few zillion > threads on PHP-General benchmarking the two and endless > arguments about which is faster/better... > > <?php > const DIR = dirname(__FILE__); > define(DIR, dirname(__FILE__); > ?> > > I personally find it kinda silly to have TWO syntaxes for > defining constants in the global space, one of which looks > like a declarative statement in C, which will lead to a whole > new swath of arguments about what is "better" > > Why is 'define' any different than 'class' or 'function'? > > Seems to me that if you want these namespace thingies that > badly, then 'define' should follow the same rules as any > other declarative keyword. > > If you 'define' something in the namespace, it's in the namespace. > > If you want global scope, 'define' it outside a namespace and > be done with it. > > Seems to me you're just complicating things with no > real-world need here... > > What are your real-world "I need this because..." code samples? > > -- > Some people have a "gift" link here. > Know what I want? > I want you to buy a CD from some indie artist. > http://cdbaby.com/browse/from/lynch > Yeah, I get a buck. So? > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php