Debugging WordPress with Xdebug - PHP Fatal Error: Uncaught Error: Call to undefined function get_header() - phpstorm

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:
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.

Related

Webpack 5 - ERROR in Error: Child compilation failed: Module parse failed: Unexpected character '�' (1:4)

I don't understand what is the problem? Webpack does not compile the project and shows the following error:
ERROR in Error: Child compilation failed: Module parse failed: Unexpected character '�' (1:4)
But I can't figure out where the error derives from, in which module or file, where to look for it? This is the error from my IDE.
At the moment, it gives only 1 error when compiling, before that there were 22 errors. Actions that could lead to this - trying to solve the problem through CSS.
After I removed everything in the code (-webkit-min-device-pixel-ratio: 2), the number of errors was reduced to 1, but I don’t understand what to do next.
My webpack 5 config: webpack.config
If someone knows how to solve this problem, or where to look for the root of evil, please help.
Problem solved! It turned out that in my webpack.config in the image processor, I did not add webp support. And when I added it on the fly, the already assembled project did not take this moment into account. As a result, after restarting the build with the npm run dev command, the updated webpack config file started working as it should! Thank you all for your attention to the issue and the desire to help figure it out! enter image description here

PhpStorm: Failed loading xebug.so

When trying to debug a single PHP script, PhpStorm keeps complaining about xebug. I assume the correct name is xdebug, but I don't find a place where I have used xebug instead of xdebug including /etc/php.d/15-xdebug.ini and /etc/php.ini. I think this is a PhpStorm bug.
Does anyone know what this is caused by and how can I fix it?
Detailed console error:
/usr/bin/php -dzend_extension=/usr/lib64/php/modules/xebug.so -dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9000 -dxdebug.remote_host=127.0.0.1 myscript.phtml
Failed loading /usr/lib64/php/modules/xebug.so: /usr/lib64/php/modules/xebug.so: cannot open shared object file: No such file or directory

Fatal error: can't use function return value in write context in /var/www/html/chamilo/main/inc/lib/api.lib.php on line 1772

I am getting the following error while installing chamilo version 1.11.6.
Fatal error: can't use function return value in write context in /var/www/html/chamilo/main/inc/lib/api.lib.php on line 1772
My php version is 7.2.
This error appears because somehow the PHP version is not 7.2 (but rather <5.5) in the context in which you are executing the page.
Since PHP 5.5, the emty() function was changed to support function results.
See http://php.net/manual/en/function.empty.php
Note:
Prior to PHP 5.5, empty() only supports variables; anything else
will result in a parse error. In other words, the following will
not work: empty(trim($name)). Instead, use trim($name) == false.
My guess is the place where you change the PHP version in your control panel doesn't affect (or didn't affect yet) the place where Chamilo is being loaded.
Ask your hosting provider, maybe?
You can place a "info.php" file with the following content at the root of Chamilo and load it directly through the browser. This will tell you what version PHP is running at in the Chamilo directory:
<?php
phpinfo();
I bet it still shows PHP 5.4...

Class PhpStorm_Codeception_ReportPrinter does not exist

I am attempting to run Codeception functional tests within PhpStorm and keep receiving an error that says a class is missing. I've scoured the internet and found nothing available for this problem except for one post https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000646104-Running-codeCeption-test-runner-causes-excpetion?sort_by=created_at . Other posts talk about how to set the argument.
I have both a phar of Codeception 2.4.1 and a composer install of it. It is using PHP version 7.1 to execute.
Searching the vendor folder returns no such class which makes me think it is supposed to be delivered or included from within PhpStorm. Not really sure, grabbing at straws.
If anyone has any exposure to this and can help with some guidance it would be much appreciated. I can run them a docker/vagrant config or from the CLI, it just cannot integrate with PhpStorm.
C:\php\php-7.1.4-Win32-VC14-x64\php.exe -d-dxdebug.remote_mode=jit C:/Users/Curtis/AppData/Local/Temp/ide-codeception.php run --report -o "reporters: report: PhpStorm_Codeception_ReportPrinter" --no-ansi --no-interaction functional
==== Redirecting to Composer-installed version in vendor/codeception ====
Codeception PHP Testing Framework v2.4.1
Powered by PHPUnit 5.7.27 by Sebastian Bergmann and contributors.
In Runner.php line 174:
Class PhpStorm_Codeception_ReportPrinter does not exist
run [-o|--override OVERRIDE] [-e|--ext EXT] [--report] [--html [HTML]] [--xml [XML]] [--tap [TAP]] [--json [JSON]] [--colors] [--no-colors] [--silent] [--steps] [-d|--debug] [--coverage [COVERAGE]] [--coverage-html [COVERAGE-HTML]] [--coverage-xml [COVERAGE-XML]] [--coverage-text [COVERAGE-TEXT]] [--coverage-crap4j [COVERAGE-CRAP4J]] [--coverage-phpunit [COVERAGE-PHPUNIT]] [--no-exit] [-g|--group GROUP] [-s|--skip SKIP] [-x|--skip-group SKIP-GROUP] [--env ENV] [-f|--fail-fast] [--no-rebuild] [--] [<suite>] [<test>]
PHP Fatal error: Uncaught RuntimeException: Command Did Not Finish Properly in C:\Users\Curtis\Projects\tripadvisor-integration\vendor\codeception\codeception\src\Codeception\Subscriber\ErrorHandler.php:101
Stack trace:
#0 [internal function]: Codeception\Subscriber\ErrorHandler->shutdownHandler()
#1 {main}
thrown in C:\Users\Curtis\Projects\tripadvisor-integration\vendor\codeception\codeception\src\Codeception\Subscriber\ErrorHandler.php on line 101
PHP Stack trace:
PHP 1. {main}() C:\Users\Curtis\AppData\Local\Temp\ide-codeception.php:0
PHP 2. require_once() C:\Users\Curtis\AppData\Local\Temp\ide-codeception.php:21
PHP 3. require() phar://C:/Users/Curtis/Projects/tripadvisor-integration/codecept.phar/autoload.php:12
PHP 4. Codeception\Application->run() C:\Users\Curtis\Projects\tripadvisor-integration\vendor\codeception\codeception\package\bin:37
PHP 5. Codeception\Application->run() C:\Users\Curtis\Projects\tripadvisor-integration\vendor\codeception\codeception\src\Codeception\Application.php:108
Fatal error: Uncaught RuntimeException: Command Did Not Finish Properly in C:\Users\Curtis\Projects\tripadvisor-integration\vendor\codeception\codeception\src\Codeception\Subscriber\ErrorHandler.php on line 101
Call Stack:
0.2024 403184 1. {main}() C:\Users\Curtis\AppData\Local\Temp\ide-codeception.php:0
0.2208 1243848 2. require_once('phar://C:/Users/Curtis/Projects/tripadvisor-integration/codecept.phar/autoload.php') C:\Users\Curtis\AppData\Local\Temp\ide-codeception.php:21
0.2862 5654840 3. require('C:\Users\Curtis\Projects\tripadvisor-integration\vendor\codeception\codeception\package\bin') phar://C:/Users/Curtis/Projects/tripadvisor-integration/codecept.phar/autoload.php:12
0.3338 8056520 4. Codeception\Application->run() C:\Users\Curtis\Projects\tripadvisor-integration\vendor\codeception\codeception\package\bin:37
0.3338 8056520 5. Codeception\Application->run() C:\Users\Curtis\Projects\tripadvisor-integration\vendor\codeception\codeception\src\Codeception\Application.php:108
RuntimeException: Command Did Not Finish Properly in C:\Users\Curtis\Projects\tripadvisor-integration\vendor\codeception\codeception\src\Codeception\Subscriber\ErrorHandler.php on line 101
Call Stack:
0.2024 403184 1. {main}() C:\Users\Curtis\AppData\Local\Temp\ide-codeception.php:0
0.2208 1243848 2. require_once('phar://C:/Users/Curtis/Projects/tripadvisor-integration/codecept.phar/autoload.php') C:\Users\Curtis\AppData\Local\Temp\ide-codeception.php:21
0.2862 5654840 3. require('C:\Users\Curtis\Projects\tripadvisor-integration\vendor\codeception\codeception\package\bin') phar://C:/Users/Curtis/Projects/tripadvisor-integration/codecept.phar/autoload.php:12
0.3338 8056520 4. Codeception\Application->run() C:\Users\Curtis\Projects\tripadvisor-integration\vendor\codeception\codeception\package\bin:37
0.3338 8056520 5. Codeception\Application->run() C:\Users\Curtis\Projects\tripadvisor-integration\vendor\codeception\codeception\src\Codeception\Application.php:108
0.6265 17565136 6. Codeception\Subscriber\ErrorHandler->shutdownHandler() C:\Users\Curtis\Projects\tripadvisor-integration\vendor\codeception\codeception\src\Codeception\Subscriber\ErrorHandler.php:0
Process finished with exit code -1
In my case, I had codeception installed both in composer global and as a project dependency.
I had to remove composer global remove codeception/codeception and go to PHPStorm -> Settings -> Languages & Frameworks -> PHP -> Test Frameworks and change my codeception executable to ~/myprojectpath/vendor/codeception/codeception/codecept

Php and Smarty3 - filemtime() [function.filemtime]: stat failed for

I'm migrating my WebAPP from Smarty2 to Smarty3. Every step is easy except one. When i display a Smarty Template ( tpl ) an Exception is thrown.
This line
Source: /path_to_file/smarty/libs/sysplugins/smarty_resource.php (773)
(this is the source coude $compiled->timestamp = #filemtime($compiled->filepath); )
raise this Exception when the file doesn't exists
filemtime() [function.filemtime]: stat failed for /path_to_templates/smarty/templates_c/219dfe732aae7bd7c0edab091e3c53f3ce86b058.file.index.tpl.php
Folder permissions:
Smarty template folder Permission : 775
Smarty Cache folder permission: 775
Folder Owners:
both ftp_user:webserver_user
I'm trying to implement different solutions but it seems not possibile to solve this issue whitout changhing Php Error Reporting or disabling my Error Handler .
How can i solve this problem without hacks ?
What you should do is not to downgrade to 3.1.1 but rather try to upgrade to 3.1.19 version. Many bugs are removed all the time so maybe in this version you won't have it.
The other thing is that you can use muteExpectedErrors method to hide file system warnings from Smarty (documentation for this function is not very clear but it affects file system warnings what is explained in error_reporting documentation). You can read at error_reporting documentation page:
Smarty 3.1.2 introduced the muteExpectedErrors() function. Calling
Smarty::muteExpectedErrors(); after setting up custom error handling
will ensure that warnings and notices (deliberately) produced by
Smarty will not be passed to other custom error handlers. If your
error logs are filling up with warnings regarding filemtime() or
unlink() calls, please enable Smarty's error muting.
Check the filesystem permission on /path_to_templates/smarty/templates_c/219dfe732aae7bd7c0edab091e3c53f3ce86b058.file.index.tpl.php
PHP does not seam to have read/write permission on that file.
Also check the permission in the /path_to_templates/smarty/templates_c/ folder. Is the PHP allowed to read list and write in there as well?