2

I am using the library gettext.php (not the standard php_gettext extension) and the error

PHP Parse error: syntax error, unexpected '!=' (T_IS_NOT_EQUAL) in /base/data/home/apps/.../libs/gettext/gettext.php(387) : eval()'d code on line 1 PHP Notice: Undefined offset: -1 in /base/data/home/apps/.../libs/gettext/gettext.php on line 422

keeps appearing on the following line:

$taskCount = Group::activeTaskCount($db, $class[Database::FIELD_CLASS_ID]);
echo ngettext(
        '%d pending task',
        '%d pending tasks',
        $taskCount);

The function Group::activeTaskCount() performs an SQL query and returns a COUNT(*) of a query.

Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
Roel Vermeulen
  • 594
  • 7
  • 15

1 Answers1

1

I found that $taskCount was actually not returning an integer value, but rather NULL. And the gettext.php library could not handle this and threw this error.

I changed the code to

echo ngettext(
        '%d pending task',
        '%d pending tasks',
        $taskCount ?: 0);

so as to foresee the NULL case.

Roel Vermeulen
  • 594
  • 7
  • 15