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

  • Home
  • SEARCH
  • 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 4060062
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:17:25+00:00 2026-05-20T15:17:25+00:00

I once saw a framework or code from some PHP that had an error

  • 0

I once saw a framework or code from some PHP that had an error handler (class or function) that would show an error message, the line number the error occurred on as well as the actual source code, if there was some sort of error in the code, it would show the line or a few lines from the actual PHP file that caused the error. it was really cool, I understand that you would not want to ever do this on a live production server/site but for debugging, it was very nice and something I have never seen before.

I cannot remember where I saw this or how it was done. If you have any ideas on how to do something similar, I would love to have a nice little class for error handling that would do stuff like that, please share any code, ideas, etc on this if you can, really appreciate any help, thank you!

  • 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-20T15:17:26+00:00Added an answer on May 20, 2026 at 3:17 pm

    What you are talking of is a stack trace, in PHP you can retrieve it with debug_backtrace().
    Most framework have their own way to display stack trace, but basicly they all use such functions.

    However, what you are really looking for is Xdebug it is a debugger and a profilter for PHP, and will let you run code step by step.

    • Stack trace with Xdebug

    Edit:

    If you want to handle error to provide your own way to work with, you have to use set_error_handler() and set_exception_handler()

    A simple example:

    <?php
        function myErrorHandler($errno, $errstr, $errfile, $errline) {
          echo "[$errno] $errstr" . PHP_EOL;
          echo "On line $errline in file $errfile" . PHP_EOL;
    
          $range = array(
              $errline - 5,
              $errline + 5,
           );
    
           $source = explode(PHP_EOL, file_get_contents($errfile));
           for ($i = $range[0]; $i <= $range[1]; ++$i) {
               if ($i === count($source)) break;
               if ($i === $errline-1) {
                   printf("%d | %s  <<<<< Here is the error\n", $i, $source[$i]);
               } else {
                   printf("%d | %s \n", $i, $source[$i]);
               }
           }
        }
    
        set_error_handler('myErrorHandler');
    
        error_reporting(E_ALL);
    
        $a = 'Setting variable $a';
    
        $obj = new Stdclass();
        $obj->foo = 'bar';
    
        // Oops I'm calling an undefined variable
        echo $undefinedVariable;
    
        $numbers = array(1,2,3,4,5);
        for($i = 0; $i < 5; ++$i) {
            $numbers[$i] = $i - 1;
        }  
    

    Trying this on cli, should show you:

    bguery@joyless:sandbox $ php debugbacktrace.php 
    [8] Undefined variable: undefinedVariable
    On line 33 in file debugbacktrace.php
    28 | $obj = new Stdclass(); 
    29 | $obj->foo = 'bar'; 
    30 |  
    31 | // Oops I'm calling an undefined variable 
    32 | echo $undefinedVariable;  <<<<< Here is the error
    33 |  
    34 | $numbers = array(1,2,3,4,5); 
    35 | for($i = 0; $i < 5; ++$i) { 
    36 |     $numbers[$i] = $i - 1; 
    37 | }   
    38 |  
    

    Note that’s a really basic usage, but it does the trick. You may need to do more work if you intend to handle E_ERROR, E_PARSE, etc. and you may need to use register_shutdown_function()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Actually i once saw some PHP code on php.net but i forgot its name
Here's some code I saw once. Can you see what's wrong with it? [updated]
I once saw this line of code: std::cout %lt;%lt; Hello world! %lt;%lt; std:: endl;
I once saw a free translation management software that was used to publish the
I once saw that was possible to do something like adding a key in
I once saw this nice little snippet of code below, here at SO: template<typename
Once I saw a DB made in MS Access that worked as a normal
Once again a very beginner-ish question, but here I go: I would like to
Once I have all the files I require in a particular folder, I would
I am interested in the PHP framework, especially by symfony and ZendFramework, but I

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.