1

When I use the __() function for translating a message in the AppController I get the following error:

PHP Parse error: syntax error, unexpected '(', expecting ')'

This is my code:

public $components = array(
    'Session',
    'Acl',
    'Auth' => array(
         'authError' => __('Did you really think you are allowed to see that?'),        
         'authorize' => array(
            'Actions' => array('actionPath' => 'controllers')
        )
    )
);

__() is supposed to be a global function, right?. Because it seems PHP is not calling it.

Sevvlor
  • 560
  • 1
  • 7
  • 24
Gonzalo
  • 185
  • 1
  • 9
  • possible duplicate of [CakePHP localization of Auth component](http://stackoverflow.com/questions/24289396/cakephp-localization-of-auth-component) – Nunser Sep 11 '14 at 17:51

2 Answers2

1

That's not an issue of php but a very basic php error. The parser is already telling you this.

You can't use functions in a property declaration.

http://php.net/manual/en/language.oop5.php

floriank
  • 25,546
  • 9
  • 42
  • 66
1

You can't call functions in a property declaration, hence the error. Call a function while setting class properties

You'll have to translate authError in another place in the app. Perhaps beforeRender or beforeFilter would work.

Community
  • 1
  • 1
Kai
  • 3,803
  • 1
  • 16
  • 33