From: "Gary ." on
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".
From: Peter Lind on
On 28 April 2010 10:57, Gary . <php-general(a)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>
From: Thijs Lensselink on
Gary . wrote:
> class Pg_Error
> {
> private static $errors =
> array(INTEGRITY_CONST_UNIQUE => 'uniqueness constraint violated');
>
Shouldn't this be:

array(self::INTEGRITY_CONST_UNIQUE => 'uniqueness constraint violated');


> ...
> public static function getMessage($ec)
> {
> $text = '';
> if (array_key_exists($ec, Pg_Error::$errors))
> {
> $text = Pg_Error::$errors[$ec];
> }
>
> return $text;
> }
> ...
> }
>
> ?
>
> Calling it, the array_key_exists call always returns false:
> $this->assertEquals('uniqueness constraint violated',
> Pg_Error::getMessage(Pg_Error::INTEGRITY_CONST_UNIQUE));
> and I can't see what I've done wrong :(
>
>

From: "Gary ." on
On 4/28/10, Thijs Lensselink wrote:
> Gary . wrote:
>> class Pg_Error
>> {
>> private static $errors =
>> array(INTEGRITY_CONST_UNIQUE => 'uniqueness constraint violated');
>>
> Shouldn't this be:
>
> array(self::INTEGRITY_CONST_UNIQUE => 'uniqueness constraint violated');

Yes, or something very like it. See Message-ID:
<y2la35643581004280018i22b3de1ag1a836e7229378b77(a)mail.gmail.com>
From: Thijs Lensselink on
Gary . wrote:
> On 4/28/10, Thijs Lensselink wrote:
>
>> Gary . wrote:
>>
>>> class Pg_Error
>>> {
>>> private static $errors =
>>> array(INTEGRITY_CONST_UNIQUE => 'uniqueness constraint violated');
>>>
>>>
>> Shouldn't this be:
>>
>> array(self::INTEGRITY_CONST_UNIQUE => 'uniqueness constraint violated');
>>
>
> Yes, or something very like it. See Message-ID:
> <y2la35643581004280018i22b3de1ag1a836e7229378b77(a)mail.gmail.com>
>
>
That message is about defining the class constant. Which is done.
But later on it is called as a normal constant. Not a class constant

Besides the fact that it should throw a notice. It also makes sure
Pg_Error::$errors looks a bit different then expected

array(1) {
["INTEGRITY_CONST_UNIQUE"]=>
string(30) "uniqueness constraint violated"
}

This makes Pg_Error::getMessage(23505) always return string(0)"" which
equals false....