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 6373133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:19:33+00:00 2026-05-25T01:19:33+00:00

I include this simple error handling function to format errors: date_default_timezone_set(‘America/New_York’); // Create the

  • 0

I include this simple error handling function to format errors:

date_default_timezone_set('America/New_York');

// Create the error handler.
function my_error_handler ($e_number, $e_message, $e_file, $e_line, $e_vars) {

    // Build the error message.
    $message = "An error occurred in script '$e_file' on line $e_line: \n<br />$e_message\n<br />";

    // Add the date and time.
    $message .= "Date/Time: " . date('n-j-Y H:i:s') . "\n<br />";

    // Append $e_vars to the $message.
    $message .= "<pre>" . print_r ($e_vars, 1) . "</pre>\n<br />";

    echo '<div id="Error">' . $message . '</div><br />';

} // End of my_error_handler() definition.

// Use my error handler.
set_error_handler ('my_error_handler');

When I include it in a script in with the following

$dom = new DOMDocument();
$dom->loadHTML($output);
$xpath = new DOMXPath($dom);

and parse a web page (in this case, http://www.ssense.com/women/designers/all/all/page_1, which I do have permission to parse) I get errors like

AN ERROR OCCURRED IN SCRIPT '/HSPHERE/LOCAL/HOME/SITE.COM/SCRIPT.PHP' ON LINE 59: 
DOMDOCUMENT::LOADHTML(): HTMLPARSEENTITYREF: NO NAME IN ENTITY, LINE: 57

and

AN ERROR OCCURRED IN SCRIPT '/HSPHERE/LOCAL/HOME/SITE.COM/SCRIPT.PHP' ON LINE 59: 
DOMDOCUMENT::LOADHTML(): TAG NAV INVALID IN ENTITY, LINE: 58

There are many errors and the page never finishes loading. However, if I do not include this error handler, the line

$dom->loadHTML($output);

does not throw any errors, and I get the results I expect in a few seconds. I assume the error handler is catching warnings related to loadHTML() that are not otherwise reported. (Even if I use

@$dom->loadHTML($output);

it still reports the errors.) How might I modify the error handler to accommodate calls to loadHTML(), or otherwise fix this problem?

  • 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-25T01:19:34+00:00Added an answer on May 25, 2026 at 1:19 am

    It’s not the custom error handler that is causing the error.

    I ran the following code without a custom error handler:

    $output = file_get_contents("http://www.ssense.com/women/designers/all/all/page_1");
    $dom = new DOMDocument();
    $dom->loadHTML($output);
    $xpath = new DOMXPath($dom);
    

    When I ran it, I got a ton of warning messages similar to the ones in your error handler.

    I think the problem you’re seeing is just that your error handler is reporting errors that PHP isn’t reporting by default.

    By default, the level of error reporting is determined by your php.ini settings, but can be overridden by using the error_reporting() function. When you set your own error handler, you have to determine for yourself what level of reporting you want to deal with. Your error handler will be called on every error and notice, and so you will output error messages for everything unless you explicitly check the error being generated against the current error_reporting() level.

    Remember that using the @ error suppression operator is just shorthand for setting error_reporting(0) for that line. For example, this line:

    @$dom->loadHTML($output);
    

    Is simply shorthand for the following:

    $errorLevel = error_reporting(0);
    $dom->loadHTML($output);
    error_reporting($errorLevel);
    

    Since normal PHP error reporting is entirely bypassed when using a custom handler, using the @ operator is meaningless since the current error_reporting() level is completely ignored. You would have to write custom code into your error handler to check the current error_reporting() level and handle it accordingly, for example:

    function my_error_handler() {
      if (error_reporting() == 0) {
        return; // do nothing when error_reporting is disabled.
      }
    
      // normal error handling here
    }
    

    My assumption is that, when not using a custom error handler, PHP is simply defaulting to an error_reporting() level which is lower than the errors being produced.

    If you add error_reporting(E_ALL | E_STRICT); to the top of your code, you will see those same errors even when you don’t have your custom error handler enabled.

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

Sidebar

Related Questions

This very simple code gives me tons of errors: #include <iostream> #include <string> int
Can anybody help me with this simple code?? #include <iostream> using namespace std; void
i want to do this simple piece of code work. #include <iostream> #include <windows.h>
This very simple code: #include <iostream> using namespace std; void exec(char* option) { cout
This is a simple code that open and print the file content. #include <stdio.h>
I have this simple c++ program #include <cstdlib> #include <iostream> #include <math.h> #include <stdlib.h>
I've prepared this simple example which is not working for me #include <stdio.h> #include
I am having some trouble getting this simple code to work: #pragma once #include
In my current error handling, I specify the Form, function and error message in
consider this simple and pointless code. #include <iostream> struct A { template<int N> void

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.