Re: What is wrong with this code?
| From: | Per Jessen | Date: | Wed, 28 Apr 2010 06:46:55 +0000 |
| Subject: | Re: What is wrong with this code? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-304695@lists.php.net to get a copy of this message | ||
Gary . wrote:
> class Pg_Error
> {
> private static $errors =
> array(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 :(
Might this be better:
public static function getMessage($ec)
{
$text = '';
if (array_key_exists($ec, $errors))
{
$text = $errors[$ec];
}
return $text;
}
--
Per Jessen, Zürich (11.2°C)