#1
  1. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,672
    Rep Power
    171

    Why do I get error:Parse error: syntax error, unexpected '(', expecting ',' or ';' in


    Hello;

    Why do I get this error:
    Parse error: syntax error, unexpected '(', expecting ',' or ';' in...
    PHP Code:
    some_class  {
        public 
    $eigtheen_years_ago date('Y'strtotime('-17 years'strtotime(date('Y'))));

    Thanks
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,143
    Rep Power
    9398
    You can't use an expression (like a function call) as the default value for a class variable. Has to be a constant. If you need an expression then set the variable in the constructor.

    Unless that's not good and you think PHP should improve it.
  4. #3
  5. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,672
    Rep Power
    171
    Originally Posted by requinix
    Unless that's not good and you think PHP should improve it.
    hahahahhahahahahhah. Finally some decent humor from the master
    Originally Posted by requinix
    You can't use an expression (like a function call) as the default value for a class variable. Has to be a constant. If you need an expression then set the variable in the constructor.
    So is this good practice?
    PHP Code:
    public function __construct()
        {
            
    parent::__construct();
            
    define('EIGHTEEN_YEARS_AGO'date('Y'strtotime('-17 years'strtotime(date('Y')))));
        } 

IMN logo majestic logo threadwatch logo seochat tools logo