Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6126913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:26:16+00:00 2026-05-23T16:26:16+00:00

Asking for decent thoughts about this: I’d like to implement some mechanism in PHP

  • 0

Asking for decent thoughts about this:

I’d like to implement some mechanism in PHP code that can run any external code and calls a callback function if one of the inclusions fails therein (include, require + *_once).

External code means that the code that is getting executed is not written by me nor is there control over it. It’s included for testing. So having detailed info about inclusions failures deeper therein is helpful.

I’m runnning into the problem that it looks impossible to have a callback when a PHP fatal error happens.

What I tried so far:

  • Registering an error handler via set_error_handler – Does not work with fatal errors.
  • Created an object instance with a __destruct() method – Is not invoked with fatal errors.
  • Registered a shutdown function – Is not called on fatal errors.

In any of these I just wanted to fetch a debug_backtrace and then work with the information given.

So question shortly is: how to track failed file inclusions from within PHP code and call a function then.

I fear the answer to the question is no from my recent tries and searches, so anything insightful is highly appreciated. Even if your answer only strengthens the “not possible” point.

Additionally it’s helpful as well if it’s possible to find out which file is going to be included, so creating a debug output before the inclusion (failing or not) could be done at least.

Remarks:

  • Preferable w/o extensions. However if something exists, I’m eager to know as well.
  • External code means that the code that is getting executed is not written by me nor is there control over it. It’s included for testing. So having detailed info about inclusions failures deeper therein is helpful.

Related:

  • How can I get PHP to produce a backtrace upon errors?
  • set_error_handler() doens’t work for FATAL error (register_shutdown_function + error_get_last)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:26:17+00:00Added an answer on May 23, 2026 at 4:26 pm

    My suggestions are untested, here are some things to try:

    If the required/included php files are classes autoload could be an option

    function __autoload($class)
    {
        // try to load
    }
    

    If you can wrap the require/includes in a try catch block setting the error handler to use exceptions might also work: Update: doesn’t work 🙁

    function exception_error_handler($errno, $errstr, $errfile, $errline ) {
        throw new ErrorException($errstr, $errno, 0, $errfile, $errline);
    }
    set_error_handler("exception_error_handler");
    

    If the code you need to test can be tested in the command line using popen and xdebug you execute the program in a separate process if pclose returns -1 you could parse the backtrace from xdebug.

        $cmd = 'php --php-ini path/php.ini file/to/run.php';
        $output = '';
        $popen  = popen($cmd, 'rb');
    
        while (!feof($popen)) {
            $output .= fread($popen, 4096);
        }
    
        if (pclose($popen) < 0) {
            // error - parse $output for xdebug backtrace
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I apologize for asking such a generalized question, but it's something that can prove
I asking about this case(replace item by position : highest with lowest etc.. ):
After asking this question about authorization, I've added a new custom attribute in an
Ok, so I feel like a complete idiot asking this, but I've been looking
Just asking if there is a way to style a cascade list like this:
Before asking this question I have googled for some time, but could not find
I would like to make a bot that can carry on a simple conversation.
A short way of asking this question is, how should be I go about
Before asking my question I would like to explain little about my architecture.My data
Just asking, and how would you go about doing this. I know there is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.