Re: Why can constants only be scalars?

From: Date: Sat, 08 May 2004 16:08:35 +0000
Subject: Re: Why can constants only be scalars?
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-9736@lists.php.net to get a copy of this message
--- Robert Cummings <robert@interjinn.com> wrote: > On Sat, 2004-05-08 at 03:19, Andi Gutmans wrote: > > At 09:16 PM 5/7/2004 -0700, Sara Golemon wrote: > > >Long ago I was told constants could only be > scalars, so I accepted it. > > >Certainly ZEND_FUNCTION(define) does the check to > ensure it's a scalar, but > > >why? > > > > > >For what I can tell a zend_constant is just a > container for an ordinary zval > > >which is refcounted and all that fun stuff. I > don't see any obvious reason > > >for this restriction, and my tests with those > restrictions removed seem safe > > >enough so far... Can someone spell it out for me > with little words? > > > > I don't remember all of the reasons, but the main > reason is that it just > > makes sense (IMO). I think constant values should > be easily seen when > > reading through source code. Having to read logic > to see what values are in > > the constants doesn't make much sense to me. I'd > use variables for that. > > If we start talking about class constants then > it's obviously even more > > important for them to be constants. You can't > evaluate values during the > > class definition as you don't have variables > defined yet. I wouldn't want > > define() to behave different from const. > > I always thought constants were about imposing an > unchanging nature to > the data and not about visual aesthetics when > reading code :/ I too > would like to see constant support of non-scalar > values. Same here. I have a number of static arrays that I use for reference data that are usually encapsulated in a function, or a global / session variable. It would be very handy to be able to define a constant array instead. - Gabriel =====

« previous php.internals (#9736) next »