Title: How to write php code that shows debug info on chrome console?
Last modified: August 22, 2016

---

# How to write php code that shows debug info on chrome console?

 *  Resolved [polev](https://wordpress.org/support/users/polev/)
 * (@polev)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/using-4/)
 * As a php developer, I was looking for something like this and it looks promising.
   
   Up to now, I used my own debug tools. I never used PHP Console.
 * Could provide an example on how to send a message to the console from my PHP 
   plugin or theme code in WordPress?
 * Thanks
 * [https://wordpress.org/plugins/wp-php-console/](https://wordpress.org/plugins/wp-php-console/)

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Thread Starter [polev](https://wordpress.org/support/users/polev/)
 * (@polev)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/using-4/#post-5684962)
 * Example code:
 *     ```
       add_action('loop_start', function($query) {
       	trigger_error(print_r($query, true));
       });
       ```
   
 *  Thread Starter [polev](https://wordpress.org/support/users/polev/)
 * (@polev)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/using-4/#post-5685067)
 * Other example code:
 *     ```
       // PHP Console autoload
       require_once dirname( __FILE__ ) . '/wp-php-console/vendor/autoload.php';
   
       // make PC object available
       PhpConsole\Helper::register();
   
       // example use of PC:debug()
       PC::debug($_SERVER);
   
       // example use of PC:db()
       add_action('wp', function ($wp) {
         PC::db($wp, 'wp');
       });
       ```
   
 *  Plugin Author [Fulvio Notarstefano](https://wordpress.org/support/users/nekojira/)
 * (@nekojira)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/using-4/#post-5685118)
 * here’s a lot on the topic:
 * [http://codex.wordpress.org/Debugging_in_WordPress](http://codex.wordpress.org/Debugging_in_WordPress)
 * you can use this link as starting point
 * for the rest, the same rules apply for debugging any php application, so you 
   can google for debug php if you want to learn more on the subject
 * as on how WordPress handles errors, it extends trigger_error with a php class
   of its own:
 * [http://codex.wordpress.org/Class_Reference/WP_Error](http://codex.wordpress.org/Class_Reference/WP_Error)
 * as for PHP Console, if WP_DEBUG and error_reporting are set to return all errors,
   PHP Console will capture those and display them in your Chrome Dev Tools javascript
   console, alongside with other javascript (not php) code notices. So, if you defined
   custom errors with trigger_error or using the WP_Error class, they will appear
   there, without you need to use PHP Console code at all.
 * if you want to test specific functions of wordpress inside a terminal, just as
   if it were a javascript terminal, you need to use the terminal, you can access
   to wordpress functions too
 *  Thread Starter [polev](https://wordpress.org/support/users/polev/)
 * (@polev)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/using-4/#post-5685310)
 * Part of this support question is obsolete as this plugin includes the registration
   option since version 1.3.0
 * See [https://github.com/nekojira/wp-php-console#register-pc-class](https://github.com/nekojira/wp-php-console#register-pc-class)
 * After you installed the plugin and enabled _Register PC Class_
    you can write
   debug statements like `PC::debug( $my_var )` to print `$my_var` to Chrome’s Javascript
   Console

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘How to write php code that shows debug info on chrome console?’ is closed
to new replies.

 * ![](https://ps.w.org/wp-php-console/assets/icon-256x256.png?rev=1070278)
 * [WP PHP Console](https://wordpress.org/plugins/wp-php-console/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-php-console/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-php-console/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-php-console/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-php-console/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-php-console/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [polev](https://wordpress.org/support/users/polev/)
 * Last activity: [11 years, 3 months ago](https://wordpress.org/support/topic/using-4/#post-5685310)
 * Status: resolved