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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:11:07+00:00 2026-05-29T12:11:07+00:00

For some reason, exceptions thrown in an __autoload function aren’t being caught when trying

  • 0

For some reason, exceptions thrown in an __autoload function aren’t being caught when trying to call a static method on a class that doesn’t exist yet (PHP 5.3.9).

See this sample code:

<?php
function __autoload($class)
{
    throw new Exception('loaded ' . $class . "\n");
}


try {
    echo "Object: ";
    $test = new Log();
}
catch (Exception $e)
{
    error_log($e->getMessage());
}

// Exception is caught with static var.
try {
    echo "Static var: ";
    Log::$blah;
}
catch (Exception $e)
{
    error_log($e->getMessage());
}

// Fatal error occures with static method.
try {
    echo "Static method: ";
    Log::blah();
}
catch (Exception $e)
{
    error_log($e->getMessage());
}

The exception is caught on the first 2 cases (new object and a static property of an unknown class), but is not caught on calling the static method.

  • 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-29T12:11:10+00:00Added an answer on May 29, 2026 at 12:11 pm

    PHP mixes errors and exceptions. In this case, the fatal error is “thrown” before the exception could be caught. It’s about priorities. Calling an undefined function and giving the fatal error has a higher priority here than handling the exception, the code already stopped (Demo). Fatal errors itself can not be catched.

    As you can not catch fatal errors with a try/catch block, your script stops at the fatal error.

    Same would be for an undefined static property of a defined class. It would trigger a fatal error as well you won’t be able to catch.

    You can however turn errors into exceptions and catch those, however this does not work with fatal errors (Demo). I assume this is the root limitation you’re running into: Fatal error brings script execution down, regardless if it appears inside a try/catch block or not. Exception handling is brought down as well.

    Additionally, PHP 5.5.0-dev and PHP 5.4.0beta2-dev crashes with a simliar to yours code example. Which makes me believe that in the upcoming PHP version there will be a bug which could be considered a flaw. It might be worth to report this against PHP 5.4.

    See also Exception slipping exception handler which illustrates your problem without the overhead of __autoload.

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

Sidebar

Related Questions

I'm trying to do a very simple INSERT using VB.NET. For some reason I'm
In my application the function CreateWindow is failing for some reason. GetLastError indicates error
I am trying to catch exceptions for my form client not being able to
For some reason I never see this done. Is there a reason why not?
For some reason when I attempt to make a request to an Ajax.net web
For some reason when I create a new namespace in Visual Studio 2008 its
For some reason, when I try to install SQL Server 2008 Express , I
For some reason, lately the *.UDL files on many of my client systems are
For some reason, Section 1 works but Section 2 does not. When run in
For some reason beyond me I can't access the mysql server on a machine.

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.