php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68216 gettext can not be used inside a class
Submitted: 2014-10-13 07:28 UTC Modified: 2014-10-14 02:13 UTC
From: klwang at klwang dot info Assigned:
Status: Not a bug Package: Gettext related
PHP Version: 5.4.33 OS: Ubuntu 10.04 LTS
Private report: No CVE-ID: None
 [2014-10-13 07:28 UTC] klwang at klwang dot info
Description:
------------
when gettext use in a class, it will be not work.
with an error message like below:

    PHP Parse error:  syntax error, unexpected '(', expecting ',' or ';' in /tmp/1.php on line 3

Test script:
---------------
<?
    class class_test{
        public static $i18n_test =  _("i18n test");
    }
    echo class_test::$i18n_test;
?>

Expected result:
----------------
the gettext can use inside a class

Actual result:
--------------
gettext can not be used inside a class

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-10-13 07:32 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2014-10-13 07:32 UTC] requinix@php.net
You cannot use a function call in the default value of a member variable - only constants and (with PHP 5.6+) constant expressions.
 [2014-10-13 07:50 UTC] klwang at klwang dot info
many thanks for your reply, but how can i internationalisation the string this case?

thanks again!
 [2014-10-13 08:02 UTC] requinix@php.net
The code you posted doesn't show what you're actually trying to do so... do it any way you'd like. Except for what you tried there with the static variable. For example, using a regular instance variable and setting it inside your constructor.
 [2014-10-14 02:13 UTC] klwang at klwang dot info
i used a constructor, and solve the problem
thanks
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Jan 29 05:01:24 2020 UTC