知道实际代码在PHP中导入的函数中断的位置

For instance, I have a simple include file that has a function:

function ViewInclude($file){
    require_once $file.'.inc.php';
}

And, another file (say index.php) that uses the function:

require_once 'inc.php';
ViewInclude('header');

When the require fails, Warning message is as:

Warning: require_once(header.inc.php): failed to open stream: No such file or directory in ..../tests/inc.php on line 4

Now, let us say, a few other files also include the inc.php file. When require fails, the error is at inc.php at some line.

Is there a way to know the actual file and line number that triggered the error? (I mean the point of include where error was originated. In above case something like: at index.php at line 62)

Something like this might help:

  function ViewInclude($file){
       if (file_exists($file)) {
           include_once($file);
       } else {
           $debug = debug_backtrace()[0];
           echo 'Failed to include file in '.$debug['file'].
                ' at line '.$debug['line'].'<br />';
       }

   }

You can use the debug_backtrace function to see the history of how the script got to that point. Use a try/catch block or set_error_handler to catch the error.