WordPress i18n in Array throws Error

This is a PHP issue, not specific to WordPress.

PHP does not allow you to declare a property as an expression. It should be a literal. So you can not call a function inside a property declararion. (see Invalid property declarations in http://php.net/manual/en/language.oop5.properties.php)

The solution is to create a getter method and use it instead. Or else you could set the propery in the __construct() method.

So, for example, doing it on construct:

class MyClass {

    private $myProperty;

    function __construct() {
        $this->myProperty = [
            'foo' => __('bar')
        ];
    }

}

Or doing this as a getter:

class MyClass {


    private function getMyProperty() {

        return [
            'foo' => __('bar')
        ];


    }

}