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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:48:22+00:00 2026-05-28T03:48:22+00:00

Well, I’m developing a framework and I’m working with __autoload classes and exception .

  • 0

Well, I’m developing a framework and I’m working with __autoload classes and exception. The problem is that on PHP 5.2 you can’t catch exceptions inside __autoload. I need catch them, there are some way to do it? PHP 5.3 it works fine!

On my framework, you have a folder that contains some classes, but the user can try load some class that not exists. The correct way is test if class_exists, but I wan’t make it optional, if user want work with exceptions. For instance:

$obj = new NotFoundClass();

In this example, if debug mode of framework is on, the client will be launched to an error page, explain about this problem (the class NotFoundClass is not found in class dir). Then only if user don’t catch manually this problem, I’ll launch to a internal error page, that tell client about this uncatched problem.

My current code is that, you can check full code on my github page or directly in the problematic file for better understanding. I don’t know if I’m clear here, please talk to me in this case.

  • 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-28T03:48:23+00:00Added an answer on May 28, 2026 at 3:48 am

    For the code in question:

     $obj = new NotFoundClass();
    

    you can do it the following:

    function __autoload($className) {
        $message = sprintf("Class '%s' not found.", $className);
        if(version_compare(PHP_VERSION, '5.3.0') >= 0)
            throw new Exception($message);
        else{
            eval("class $className {public function __construct() {
                throw new Exception(\"$message\");
            } }");
        }
    }
    
    $obj = new NotFoundClass();
    

    Which will make it throwing the exception regardless if it’s PHP 5.2 or 5.3; Demo.

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

Sidebar

Related Questions

Well, I am storing variables inside of a class that will be used for
Well the problem is that I have this enum, BUT I don't want the
well my problem is that, i have a form, which i want to validate
Well im here because i have a problem. i have code that was created
Well, it seems simple enough, but I can't find a way to add a
Well this is incredibly frustrating. After being nagged by Rails that I need to
Well, here we are. Yet another proposed practice that my C++ book has an
Well before anyone claims that theres a duplicate question... (I've noticed that people who
well I think I know what the problem is. I am just having a
Well I'm working on a school project, and I uploaded my script to send

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.