We're now going to insert some faulty code to simulate errors in our application, and then initiate a debugging session in PhpStorm from Z-Ray.
Inserting Example Code
This step includes the example code for simulating errors in the WordPress application.
|
To insert example code:
- In PhpStorm, open the 'general-template.php' file located in the 'wp-includes' folder.
- Insert the following changes to lines 1-47 in your code (changes are marked in red):
/** * General template tags that can go anywhere in a template. * * @package WordPress * @subpackage Template */ function getFilePath() { return null; } /** * Load header template. * * Includes the header template for a theme or if a name is specified then a * specialised header will be included. * * For the parameter, if the file is called "header-special.php" then specify * "special". * * @since 1.5.0 * * @uses locate_template() * * @param string $name The name of the specialised header. */ function get_header( $name = null ) { /** * Fires before the header template file is loaded. * * The hook allows a specific header template file to be used in place of the * default header template file. If your file is called header-new.php, * you would specify the filename in the hook as get_header( 'new' ). * * @since 2.1.0 * @since 2.8.0 $name parameter added. * * @param string $name Name of the specific header file to use. */ do_action( 'get_header', $name ); $templates = array(); $name = (string) $name; $filename = getFilePath(); $file = file_get_contents($filename, true);
- Save your changes.
|
|
|
Debugging from Z-Ray
|
To debug/profile your from Z-Ray:
- In your browser, reload the page.
As soon and the page loads, Z-Ray indicates that the page has triggered errors and monitor events. What is an event?
- Open the Monitor Events panel.
- Notice that both the PHP Error and Function Error events are related to the file_get_contents() function.
- Open the adjacent Warnings and Errors panel.
- Hover over the file name. Z-Ray pinpoints the exact location in your project causing the error.
- In PhpStorm, insert a breakpoint on line 47 in the 'general-template.php' file.
- In Z-Ray, click the Debug icon
on the right, and select Debug current page. A debugging session is initiated in PhpStorm, pausing on the first line of code.
- Click the Resume icon
in the Debug window. Debugging will stop at the defined breakpoint.
- In the Variables window, PhpStorm tells us that the filename variable is receiving a null value.
- Continue debugging - remove the breakpoint on line 47, and insert a new one on line 46.
- Repeat steps 7-8 to debug the application again.
Debugging stops at the defined breakpoint on line 46.
- Click the Step Into icon
in the Debug window. PhpStorm displays the problematic expression in the code.
|