Re: What is wrong with this code?
| From: | Peter Lind | Date: | Wed, 28 Apr 2010 09:06:45 +0000 |
| Subject: | Re: What is wrong with this code? | ||
| References: | 1 2 3 4 5 6 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-304703@lists.php.net to get a copy of this message | ||
On 28 April 2010 10:57, Gary . <php-general@garydjones.name> wrote:
> On 4/28/10, Jochem Maas wrote:
>>> >> class Pg_Error
>>> >> {
>>> const INTEGRITY_CONST_UNIQUE = '23505';
>>
>> this is a class constant
>>
>>> >> private static $errors =
>>> >> array(INTEGRITY_CONST_UNIQUE => 'uniqueness
>>> constraint
>>> violated');
> [...]
>> unfortunately you cannot use a classes
>> own
>> constants in the definition of the $errors var
>
> Huh? IWFM. Is it defined in the language that it does not work, or
> might not work depending on the runtime environment? IMO it should
> work (given the declaration order) but I know statics do have a
> tendency (certainly in other laguages) to be somewhat "special".
>
Shouldn't be any problems using a classes constants in the definition
of an array in the same class. However, to avoid possible extra work
down the line, I wouldn't use Pg_Error::YOUR_CONSTANT inside the
class, I'd use self::YOUR_CONSTANT
Regards
Peter
--
<hype>
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51
</hype>