Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:9730 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 38578 invoked by uid 1010); 8 May 2004 07:19:53 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 38477 invoked from network); 8 May 2004 07:19:52 -0000 Received: from unknown (HELO mail.zend.com) (192.117.235.230) by pb1.pair.com with SMTP; 8 May 2004 07:19:52 -0000 Received: (qmail 8491 invoked from network); 8 May 2004 07:19:51 -0000 Received: from localhost (HELO AndiNotebook.zend.com) (127.0.0.1) by localhost with SMTP; 8 May 2004 07:19:51 -0000 Message-ID: <5.1.0.14.2.20040508101314.02ddd728@127.0.0.1> X-Sender: andi@127.0.0.1 X-Mailer: QUALCOMM Windows Eudora Version 5.1 Date: Sat, 08 May 2004 10:19:44 +0300 To: "Sara Golemon" ,internals@lists.php.net In-Reply-To: <20040508041437.32151.qmail@pb1.pair.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed Subject: Re: [PHP-DEV] Why can constants only be scalars? From: andi@zend.com (Andi Gutmans) References: <20040508041437.32151.qmail@pb1.pair.com> 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