|  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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: klwang at klwang dot info
New email:
PHP Version: OS:


 [2014-10-13 07:28 UTC] klwang at klwang dot info
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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-10-13 07:32 UTC]
-Status: Open +Status: Not a bug
 [2014-10-13 07:32 UTC]
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]
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
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sat Jun 03 08:03:39 2023 UTC