#1
  1. A Change of Season
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    3,007
    Rep Power
    175

    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. Confusing Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    15,923
    Rep Power
    9570
    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 Loyal (3000 - 3499 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    3,007
    Rep Power
    175
    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