PHP致命错误:当当前类作用域在cakehp3.x中没有父级时,无法访问父级


PHP Fatal error: Cannot access parent:: when current class scope has no parent in cakephp 3.x

我在cakehp3.x中发现了上述问题。

namespace App'Controller;
class UsersController extends AppController
{
    public function index()
    {
        $users = $this->Users->find('all');
        print_r($users); // <-- print_r creates a problem in cakephp 3.x
        $this->set('users', $users);
    }
}

我运行了上面的代码,发现了以下错误:

Error: Cannot access parent:: when current class scope has no parent
File /var/www/html/cakephp-3-1-5/vendor/cakephp/cakephp/src/ORM/Query.php
Line: 1018

此错误是由于print_r引起的。我也尝试过pr、var_dump,但也存在同样的问题。

然后在评论print_r之后,它关闭了apache并显示"连接已重置",然后我需要重新启动我的apache服务,然后它就可以正常工作了。

所以我认为这个问题是print_r。但我不知道真正的问题是什么,因为作为一名开发人员,我需要调试我的结果集。这里它限制我使用print_r、pr和var_dump。

我的目的是显示结果集。

结果集

(int) 0 => object(Cake'ORM'Entity) {
    'id' => (int) 1,
    'title' => 'Distance between two addresses using Google Maps API and PHP',
    'description' => 'Calculate distance between two addresses........',
    'created' => object(Cake'I18n'Time) {
        'time' => '2015-11-30T11:50:21+0000',
        'timezone' => 'UTC',
        'fixedNowTime' => false
    },
    'modified' => object(Cake'I18n'Time) {
        'time' => '2015-12-01T06:32:17+0000',
        'timezone' => 'UTC',
        'fixedNowTime' => false
    },
    'status' => true,
    '[new]' => false,
    '[accessible]' => [
        '*' => true
    ],
    '[dirty]' => [],
    '[original]' => [],
    '[virtual]' => [],
    '[errors]' => [],
    '[repository]' => 'Posts'
},
(int) 1 => object(Cake'ORM'Entity) {
    'id' => (int) 2,
    'title' => 'Ajax Pagination in CodeIgniter Framework',
    'description' => 'CodeIgniter have the pagination library by........',
    'created' => object(Cake'I18n'Time) {
        'time' => '2015-11-30T11:50:21+0000',
        'timezone' => 'UTC',
        'fixedNowTime' => false
    },
    'modified' => object(Cake'I18n'Time) {
        'time' => '2015-11-30T11:50:21+0000',
        'timezone' => 'UTC',
        'fixedNowTime' => false
    },
    'status' => true,
    '[new]' => false,
    '[accessible]' => [
        '*' => true
    ],
    '[dirty]' => [],
    '[original]' => [],
    '[virtual]' => [],
    '[errors]' => [],
    '[repository]' => 'Posts'
}

cakehp3.x有问题吗?cakehp3.x的释放稳定吗?我可以用它作为开发框架吗?还是用以前的2.x版本?

谢谢。

经过一些研究,我发现cakehp3.x到目前为止存在一些分割错误。因此,我们可以使用pj($var)debug($var)来代替print_r(), pr()

谢谢你的做法。