解析错误:语法错误,出现意想不到的'(',期望为','或';' [英] Parse error: syntax error, unexpected '(', expecting ',' or ';' in

查看:854
本文介绍了解析错误:语法错误,出现意想不到的'(',期望为','或';'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到以下解析错误:

解析错误:语法错误,出现意想不到的'(',期望为','或';' H:\ Programs \ USBWebserver 第7行的v8.5 \ 8.5 \ root \ oopforum \ func \ register.class.php

Parse error: syntax error, unexpected '(', expecting ',' or ';' in H:\Programs\USBWebserver v8.5\8.5\root\oopforum\func\register.class.php on line 7

与我的课程中的以下代码行有关:

which relates to the following line of code in my class:

private $random_name = rand(1000,9999).rand(1000,9999).rand(1000,9999).rand(1000,9999);

我看不到为什么这行代码会导致解析错误?

I can not see why this line of code would cause a parse error?

以下是一些周围的代码:

Here is some surrounding code:

class register{
    public $post_data = array();
        private $dbh;
        private $allowed_type = array('image/jpeg','image/png','image/gif');
        private $random_name = rand(1000,9999).rand(1000,9999).rand(1000,9999).rand(1000,9999);
        private $path = 'img/thumb_/'.$random_name. $_FILES['file']['name'];
        private $max_width = 4040;
        private $max_height = 4040;
        private $max_size = 5242880;
        private $temp_dir = $_FILES['file']['tmp_name'];
        private $image_type = $_FILES['file']['type'];
        private $image_size = $_FILES['file']['size'];
        private $image_name = $_FILES['file']['name'];
        private $image_dimensions = getimagesize($temp_dir);
        private $image_width = $image_dimensions[0]; // Image width
        private $image_height = $image_dimensions[1]; // Image height
        private $error = array();

        public function __construct($post_data, PDO $dbh){
        $this->post_data = array_map('trim', $post_data);
        $this->dbh = $dbh;
        }
}

是什么导致解析错误?

推荐答案

您无法将成员变量初始化为非静态的任何内容,而您正在尝试调用函数.

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

手册:

此声明可能包含初始化,但这 初始化必须是一个常数值-也就是说,它必须能够 在编译时进行评估,并且不得依赖于运行时 信息以便进行评估.

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);
}

这篇关于解析错误:语法错误,出现意想不到的'(',期望为','或';'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆