Re: Referencing a "constant" class variable

From: Date: Wed, 06 Oct 2004 21:14:39 +0000
Subject: Re: Referencing a "constant" class variable
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-198781@lists.php.net to get a copy of this message
On October 6, 2004 15:34, Chris Boget wrote: > Unfortunately, in PHP4.3.2 that doesn't seem to be working... :( > Does anyone know how I can access a class' variable w/o having > to instantiate an object of the class? This is more to the point of > what I'm trying to do: > > Since PHP4 doesn't have enums, I'm doing this: > > class MyEnums { > var $this = 'This'; > var $that = 'That'; > var $other = 'Other'; > } Chris, A work around I've used in the past has been to use a keyed array such as: $MyEnums = array( "is" => "This", "at" => "That", "er" => "Other" ); Then you can refer to them like: echo($MyEnums["is"]); // Prints "This" Just an idea. HTH -- Regards, David Bevan We could learn a lot from crayons: some are sharp, some are pretty, some are dull, some have weird names, and all are different colors....but they all exist very nicely in the same box.

« previous php.general (#198781) next »