Home > php教程 > PHP源码 > Fatal error: Access level to xxx must be protected 错误解决

Fatal error: Access level to xxx must be protected 错误解决

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-08 17:20:02
Original
3896 people have browsed it

php出现Fatal error: Access level to xxx must be protected 错误我们可如何来解决呢,对于这个问题下面我们就一起来看看它的解决办法.

<script>ec(2);</script>

今天程序突然出现这样的报错
Fatal error: Access level to xxx must be protected (as in class xxx) or weaker in xxx.php on line

原因是子类中定义了与父类一样的方法名

子类:
private function return_json($message,$result='true') {
        $data = array();
        $data['result'] = $result;
        $data['message'] = $message;
        self::echo_json($data);
}

private function echo_json($data) {
    if (strtoupper(CHARSET) == 'GBK'){
        $data = Language::getUTF8($data);//网站GBK使用编码时,转换为UTF-8,防止json输出汉字问题
    }
    echo json_encode($data);
}

父类:

/**
 * 返回json状态
 */
protected function return_json($message,$result='true') {
    $data = array();
    $data['result'] = $result;
    $data['message'] = $message;
    self::echo_json($data);
}

protected function echo_json($data) {
    if (strtoupper(CHARSET) == 'GBK'){
        $data = Language::getUTF8($data);//网站GBK使用编码时,转换为UTF-8,防止json输出汉字问题
    }
    echo json_encode($data);die;
}

解决办法

把子类中的private 改成 protected,或者避免方法重名。这里例子中很显然是相同的方法进行了重复的定义,子类删除这两个方法即可。

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template