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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:04:55+00:00 2026-06-04T07:04:55+00:00

According to http://php.net/manual/en/language.oop5.autoload.php the magic function __autoload() was deprecated as of PHP 7.2.0 and

  • 0

According to http://php.net/manual/en/language.oop5.autoload.php the magic function __autoload() was deprecated as of PHP 7.2.0 and removed as of PHP 8.0.0.

The official alternative is spl_autoload(). See http://www.php.net/manual/en/function.spl-autoload.php. But the PHP manual does not explain the proper use of this baby.

My question: How to replace this (my automatic class autoloader) with a version with spl_autoload()?

function __autoload($class) {
    include 'classes/' . $class . '.class.php';
}

Problem: I cannot figure out how to give that function a path (it only accepts namespaces).

By the way, there are a lot of threads regarding this topic here on SO, but none gives a clean & simple solution that replaces my sexy one-liner.

  • 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-06-04T07:04:55+00:00Added an answer on June 4, 2026 at 7:04 am

    You need to register autoload functions with spl_autoload_register. You need to provide a “callable”. The nicest way of doing this, from 5.3 onwards, is with an anonymous function:

    spl_autoload_register(function($class) {
        include 'classes/' . $class . '.class.php';
    });
    

    The principal advantage of this against __autoload is of course that you can call spl_autoload_register multiple times, whereas __autoload (like any function) can only be defined once. If you have modular code, this would be a significant drawback.


    2018 update to this: there shouldn’t really be that many occasions when you need to roll your own autoloader. There is a widely accepted standard (called PSR-4) and several conforming implementations. The obvious way of doing this is using Composer.

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

Sidebar

Related Questions

According to: http://www.php.net/manual/en/function.filectime.php In most Unix filesystems, a file is considered changed when its
According to the comment in PHP manual about Copy(): http://php.net/manual/en/function.copy.php The copy() will change
so according to this: http://php.net/manual/en/function.getimagesize.php If accessing the filename image is impossible, or if
According to http://www.php.net/manual/en/mysqlnd.overview.php MySQLND now supports SSL Does anyone know of any examples of
According to http://www.codeguru.com/forum/showthread.php?t=463663 , C#'s getHashCode function in 3.5 is implemented as: public override
I've got a PHP-fpm setup on nginx setup according to this article: http://interfacelab.com/nginx-php-fpm-apc-awesome/ PHP
According to articles like: http://www.oreillynet.com/onjava/blog/2007/06/easy_ajax_with_struts_2.html and http://www.firstpartners.net/kb/index.php/Easy_Ajax_using_Struts_2 it should be easy (out of the
According to http://www.codingforums.com/archive/index.php/t-98569.html , the date validation could be done using the javascript's date
my site is all happily Gzipped according to: http://www.gidnetwork.com/tools/gzip-test.php However when I run it
the specific example i am referring to is this site http://www.iamextreme.net/category.php?CategoryId=1&SubCategoryId=0&SortBy=name notice the sort

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.