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

后端 未结 2 1357
慢半拍i
慢半拍i 2020-11-29 10:04

I am recieveing the following parse error:

Parse error: syntax error, unexpected \'(\', expecting \',\' or \';\' in H:\\Programs\\USBWebserver v8.

相关标签:
2条回答
  • 2020-11-29 10:37

    You can't do this:

    private $image_dimensions = getimagesize($temp_dir);
    

    Functions, variables, and anything else not static can't be called to set class variables.

    0 讨论(0)
  • 2020-11-29 10:43

    You can't initialize member variables to anything that is not static, and you're trying to call a function.

    From the manual:

    This 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.

    The workaround is to set your variable in the constructor:

    private $random_name;
    public function __construct() { 
        $this->random_name = rand(1000,9999).rand(1000,9999).rand(1000,9999).rand(1000,9999);
    }
    
    0 讨论(0)
提交回复
热议问题