Fatal error:access level to XXX must is protected error resolution

Source: Internet
Author: User
Tags json

Today, the program suddenly appears to have this error
Fatal error:access level to XXX must is protected (as in class XXX) or weaker in xxx.php

The reason is that the same method name as the parent class is defined in the subclass

Sub class:
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);//Site GBK when encoding is used, convert to UTF-8 to prevent JSON from outputting kanji problems
}
echo Json_encode ($data);
}

Parent class:

/**
* Return to JSON state
*/
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);//Site GBK when encoding is used, convert to UTF-8 to prevent JSON from outputting kanji problems
}
echo Json_encode ($data);d ie;
}

Solutions

The private in the handle class is changed to protected, or avoid the duplicate of the method. In this example, it is obvious that the same method is used to define the duplicate, and the subclass deletes the two methods.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.