-1

Possible Duplicate:
Parse error: syntax error, unexpected '(', expecting ',' or ';' in

I am doing the following:

<?php
class JConfig {
    public $var = get_cfg_var('mySetting');
}
?>

If I do that I received a compile error that says:

syntax error, unexpected '(', expecting ',' or ';'

If I do echo get_cfg_var('mySetting') outside the class it works just fine.
If I assign get_cfg_var('mySetting') to a local variable it works just fine.

Anyone has any idea why I can't assign it to a instance variable?

Community
  • 1
  • 1

1 Answers1

1

From the documentation:

[Property] declaration may include an initialization, but this initialization must be a constant value--that is, it must be able to be evaluated at compile time and must not depend on run-time information in order to be evaluated.

You will need to initialize that value from the class constructor or from somewhere else in your code.