Re: Why can constants only be scalars?
| From: | Andi Gutmans | Date: | Sat, 08 May 2004 07:19:44 +0000 |
| Subject: | Re: Why can constants only be scalars? | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-9730@lists.php.net to get a copy of this message | ||
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. Andi