0

I'm trying to debug a WordPress-installation using Xdebug and PhpStorm.

If I write this in the top of functions.php:

[line 1]: <?php
[line 2]: $test = '1234';

And set a breakpoint on line 2, and run 'Debug functions.php', then I hit that breakpoint and I'm able to debug that breakpoint in PhpStorm. So far so good!

But if I move it down, to the bottom of functions.php, and do the same thing, then I get the error:

PHP Fatal error: Uncaught Error: Call to undefined function add_action() in /path/to/project/wp-content/themes/my-theme-name/functions.php:44
#0 {main}
Stack trace:
thrown in /path/to/project/wp-content/themes/my-theme-name/functions.php on line 44

Line 44 looks like this:

[line 43]: include_once( __DIR__ . '/classes/AdminNotice.php' );
[line 44]: add_action('admin_notices', [new AdminNotice(), 'displayAdminNotice']);

I've also tried debugging other files.

Like page.php. Same thing - if I add my demo-code (and breakpoint) in the top, then it works. But if I move it to the bottom, then it stumbles over get_header(). The error:

PHP Fatal error: Uncaught Error: Call to undefined function get_header() in /path/to/project/wp-content/themes/my-theme-name/page.php:6
Stack trace:
#0 {main}
thrown in /Users/zethodderskov/Code/Greenmind/V2-1__local/app/public/wp-content/themes/my-theme-name/page.php on line 6

And line 6 looks like this:

get_header(); ?>

And if I set a breakpoint in an imported class, then it doesn't stop at that breakpoint (even though I'm 100% sure that it reaches that part of the code).

This may be because it's reached during a POST-request. Hmm... I hate being a noob.


Useful intel

  • I've tried a bunch of times setting Xdebug up, but I've never been successful. This is the closest I've gotten. So it might be some stupid blunder.
  • I'm using PHP v. 8.0.6, Xdebug version 3.0.4 and PhpStorm version 2020.3.1 - Build #PS-203.6682.180.
  • The remote server is a Cloudways-server.
  • I've defined WordPress (and WooCommerce) as external libraries (Languages & Frameworks >> PHP). So PhpStorm should know the WordPress-functions. And I can CMD+click on the WordPress-functions and see the function definitions.
  • If I go to 'Run' >> 'Web Server Debug Validation' and click 'Validate', then it shows all green ticks.
  • The guide I've followed the most is this Zero-configuration Xdebug debugging.
  • Here is the contents of my local php.ini-file:
...
... Omitted lines
...

[xdebug]
zend_extension="/usr/local/lib/php/pecl/20200930/xdebug.so"
xdebug.mode=debug
xdebug.client_host=12.123.123.123 (IP to Cloudways-server)
xdebug.client_port=9003

; End of file
  • In Cloudways, I've added these lines to the php.ini on the remote server (under 'Application Settings' >> 'PHP FPM Settings'):
php_admin_value[display_errors]=on
php_admin_value[memory_limit]=2048M
php_value[xdebug.remote_enable]=1
php_value[xdebug.mode]=debug
php_value[xdebug.client_host]=87.116.38.66

Answer to comments 1

As @LazyOne pointed out, then I might be debugging a single file, whereas I'm trying to debug the entire project running.

I'm just unsure how to do that. If I go to 'Run' >> 'Edit configurations' (under debug), then I reach this dialog box:

PhpStorm Xdebug edit configuration

And I'm not really sure what I'm supposed to do here, since it 'forces me' to define which file I'm trying to debug.

4

0 回答 0