开发者

Is there a way to easily open/edit the files shown in the PHP errors in your browser?

Is there a way (through a browser addon or other means) to easily open the files shown to be caus开发者_运维百科ing errors?

For example, it would be nifty to be able to click on the Notice below and open the file in my IDE, rather than having to go back to my IDE and look for the file when the notice appears.

Notice: Undefined index: xyz in C:\xampp\htdocs\index.php on line 141


You could possibly do something using set_error_handler and register_shutdown_function (to handle fatal errors) to intercept the errors and display them differently. The example below isn't a fully functional of what you're asking but should point you in the right direction. I'll leave it up to you to figure out how to launch the program of your choice.

<?php

function error_handler($errno, $errstr, $errfile, $errline)
{
  echo $errstr . ' in <a href="file://' . $errfile . '">'.$errfile.'</a> on line ' . $errline . PHP_EOL;
}

function shutdown_handler()
{
  $err = error_get_last();

  // Fatal errors don't trigger the error handler so trigger the error handler manually.
  if ( ! empty($err['type']) && $err['type'] === E_ERROR )
    error_handler($err['type'], $err['message'], $err['file'], $err['line']);
}

set_error_handler('error_handler');
register_shutdown_function('shutdown_handler');

// The following 2 line throw errors.
preg_replace('invalid regex', '', 'Sample');
stack('overflow');


After some further research I have found that installing Xdebug and making use of the file_link_format configuration variable was exactly what I needed.

This forum thread helped me to get it set up with Netbeans which is the IDE I am using but you will be able to get it to work with any IDE/text editor with a change to the batch file they suggest.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜