Re: What good are constants if you can't use them in an array?

From: Date: Wed, 02 Aug 2006 22:56:02 +0000
Subject: Re: What good are constants if you can't use them in an array?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-240026@lists.php.net to get a copy of this message
On Wed, 2006-08-02 at 15:24 -0700, Daevid Vincent wrote: > *sigh* > > Why is PHP so lame... Why are you trolling on the PHP list? > > <?php > class PHPISLAME > { > const STOP = 0; > const START = 1; > const PAUSE = 2; > > public static $STATES = array( > STOP => 'Stopped', > START => 'Started', > PAUSE => 'Paused' > ); > > public static $STATESHACK = array( > 0 => 'Stopped', > 1 => 'Started', > 2 => 'Paused' > ); > } > > print_r(PHPISLAME::$STATES); > > print_r(PHPISLAME::$STATESHACK); > ?> > > What is this crap!!?: > Array ( [STOP] => Stopped [START] => Started [PAUSE] => Paused ) > > Array ( [0] => Stopped [1] => Started [2] => Paused ) PHP assumes type string for for undefined constants. If you weren't so lame and had error reporting at a high enough level you would have been well notified. My guess is that you are referencing a constant before the class has been declared. You are expecting that the class information exists at the same time of declaration. While I'm sure there are ways to make it happen, it's up to you to ask the PHP internals to solve your chicken egg problem... and I doubt it will happen with your lame attitude. Cheers, Rob. -- .------------------------------------------------------------. | InterJinn Application Framework - http://www.interjinn.com | :------------------------------------------------------------: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `------------------------------------------------------------'

« previous php.general (#240026) next »