Fatal error: Access level to xxx must be protected 错误解决
发布:smiling 来源: PHP粉丝网 添加日期:2016-08-25 13:41:04 浏览: 评论:0
php出现Fatal error: Access level to xxx must be protected 错误我们可如何来解决呢,对于这个问题下面我们就一起来看看它的解决办法.
今天程序突然出现这样的报错
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);
- } //phpfensi.com
- protected function echo_json($data) {
- if (strtoupper(CHARSET) == 'GBK'){
- $data = Language::getUTF8($data);//网站GBK使用编码时,转换为UTF-8,防止json输出汉字问题
- }
- echo json_encode($data);die;
- }
解决办法:
把子类中的private 改成 protected,或者避免方法重名。这里例子中很显然是相同的方法进行了重复的定义,子类删除这两个方法即可。
Tags: Fatal error Access protected
相关文章
- ·Fatal error: Call to undefined function curl_init(2013-11-28)
- ·Fatal error: Cannot redeclare 常见问题(2013-11-29)
- ·php中Fatal error: Class ZipArchive not found的解决办法(2013-12-02)
- ·php错误Fatal error: Out of memory (allocated 262144)(2013-12-04)
- ·Fatal error: Out of memory (allocated 786432)提示解决办法(2013-12-04)
- ·Fatal error: Maximum execution time of 30 错误(2013-12-04)
- ·Fatal Error: Allowed memory size of 123456789 bytes exhausted(2013-12-04)
- ·PHP 报错 Fatal error: Class 'COM' not found in(2013-12-05)
- ·PHP Fatal error: Cannot use object of type stdClass as array in错误(2014-09-20)
- ·php程序执行超时解决办法(Fatal error: Maximum execution time of 30)(2014-09-21)
- ·php提示Fatal error: Call to undefined function imagecreate()(2014-09-21)
- ·Fatal error: Allowed memory size of 134217728 bytes exhauste(2014-09-21)
- ·php Fatal error: Call to undefined function imagecreatefromjpeg()(2015-04-04)
- ·php Fatal error: Call to undefined function mb_convert_encoding()(2015-04-04)
- ·php提示Fatal error: Call to undefined function openssl_x509_parse()(2015-04-04)
- ·php使用ZipArchive提示Fatal error: Class ZipArchive not found in(2015-04-09)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)