PHP warning if $string is false in translate() function

Bug #773255 reported by Nick Freear
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
php-gettext
New
Undecided
Unassigned

Bug Description

I suggest its better if the function quietly returns when $string is false, as opposed to outputting a warning - v1.0.11 of php-gettext - gettext.php: line 258:

ERROR - 2011-04-29 13:06:06 --> Severity: Warning --> array_key_exists() [<a href='function.array-key-exists'>function.array-key-exists</a>]: The first argument should be either a string or an integer ...cloudengine/system/application/libraries/php-gettext/gettext.php 258

Github Gist to follow.

Revision history for this message
Данило Шеган (danilo) wrote :

Nick, thanks for the bug report and provided fix. The fix, though, seems weird. Wouldn't PHP evaluate empty string to false, and thus !$string to true as well? (Empty string is a special string in gettext world indicating the PO file header)

Just so I understand the reasons, why would you want to pass false to a translate() function? I am not opposed to accepting it, but I need to understand more of the reasons before I do that (i.e. what about true, or integers, or...).

Please set the bug state back to 'new' after you respond. Thanks!

Changed in php-gettext:
status: New → Incomplete
Revision history for this message
Nick Freear (nfreear) wrote :

Hi,

Thanks for the swift reply!

I suspect the issue I had was with a configuration string in our software (CloudEngine), which is sometimes empty but needs translating (when not empty),
* https://bitbucket.org/cloudengine/cloudengine/src/tip/system/application/config/cloudengine.dist.php#cl-14

In any case I've put a fix in our internationalization library:
* https://bitbucket.org/cloudengine/cloudengine/src/tip/system/application/libraries/MY_Language.php#cl-352
* https://bitbucket.org/cloudengine/cloudengine/issue/173/update-php-gettext-3rd

Maybe do a specific test for $string===false ? A number of false conditions (maybe not empty string) would cause a PHP warning in array_key_exists.

I've updated my Gist - I hope that helps. Thanks for your work on the library!

Best wishes,

Nick

CloudEngine - create your social site (shameless plug!)
http://getcloudengine.org

Changed in php-gettext:
status: Incomplete → New
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.