Home > Mobile >  __debuginfo error with Xdebug and CakePHP 4
__debuginfo error with Xdebug and CakePHP 4

Time:05-26

I'm trying to use XDebug on VSCode to debug a PHP 8.1 / CakePHP 4.3 project hosted on a local Docker container, but it always fails with this error:

2022-05-25 12:11:36 error: [Cake\Error\FatalErrorException] __debuginfo() must return an array in /var/www/repo/public/vendor/cakephp/cakephp/src/ORM/BehaviorRegistry.php on line 78
Stack Trace:
- /var/www/repo/public/vendor/cakephp/cakephp/src/Error/BaseErrorHandler.php:119
- [main] - [internal], line ??

This is my launch.json config:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for Xdebug",
            "type": "php",
            "request": "launch",
            "port": 9003,
            "stopOnEntry": true,
            "pathMappings": {
              "/var/www/repo": "<path/to/my/local/project>"
             }
        },
   ]
}

If I set "stopOnEntry": true, XDebug correctly stops at the first line of the entrypoint of my project (I.E. the webroot/index.php file), but when I get to the $server->emit($server->run()); line, I get the error.

Same if I set "stopOnEntry": false, and set a breakpoint somewhere in my project (I.E. Application.php or Controller/AppController.php). No matter where I put the breakpoint, I always get the same error about __debuginfo().

What's going on here? Is CakePHP somehow incompatible with XDebug, because internally the framework is using the __debuginfo() incorrectly? Or does CakePHP 4 actually work with XDebug, and I'm doing something wrong in my own code (though I can't understand what or where) and the error is just cryptic? Does anybody have any experience with getting XDebug to work on a CakePHP 4 project correctly?

CodePudding user response:

because internally the framework is using the __debuginfo incorrectly

Yes, that is likely it.

__debugInfo() must return an array.

Xdebug invokes __debugInfo() to obtain information information for some variables. If during the normal execution of a script this is never done, then the error will not show up, but because Xdebug does use it, you will run into this. I would suggest you report this to the Cake people as it is only something they can fix.

CodePudding user response:

The problem is that your PHP version is 8.1.x and the CakePHP version that you use assumes an older PHP version which was more lenient with type enforcing of the types. You have several options:

  • you can downgrade to an older version of PHP
  • you can fix the code in CakePHP for the time being
  • you can send an error report to CakePHP

With PHP 8.1.x the : sometype specifications are enforced and they were not enforced previously.

  • Related