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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:10:00+00:00 2026-06-18T09:10:00+00:00

This is more for my own personal edification than anything else but, this is

  • 0

This is more for my own personal edification than anything else but, this is something that has always bothered me: Why specifically can’t PHP perform “autoloading” while in CLI mode?

I’ve been reading this disclaimer for years, but I’ve never read anything that touches on why:

http://php.net/manual/en/language.oop5.autoload.php:

Note: Autoloading is not available if using PHP in CLI interactive mode.

Does anyone know what is preventing PHP, as a language, from autoloading while working in CLI mode?

  • 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-18T09:10:02+00:00Added an answer on June 18, 2026 at 9:10 am

    Autoloading on the command line works. Do note the mention of “interactive”.

    PHP comes with two interactive modes, but unfortunately both of them are invoked by using php -a on your command shell.

    If PHP is compiled with readline support, you get the “interactive shell”. In this mode, every command is evaluated nearly instantly, and you also get instant feedback about any parsing errors.

    In this mode, autoloading works.

    The other mode is called “interactive mode”. This mode is void of any fancy stuff, it only emits a short message, and then you basically write a PHP script – and nothing gets done unless you close the STDIN. Only then the written code gets parsed and executed. And this is the only case where the __autoload() function is not called for unknown classes.

    Example for an interactive shell session (using PHP 5.3.2 on Linux):

    vagrant@lucid32:/etc/apache2$ php -a
    Interactive shell
    
    php > function __autoload($classname) {
    php { echo "Autoload $classname";
    php { eval("class $classname{}");
    php { return true;
    php { }
    php > new Bar();
    Autoload ▒▒Bar
    php > new FooBar();
    Autoload ▒▒FooBar
    php > var_dump($a = get_declared_classes());
    array(123) {
    [0]=>
    string(8) "stdClass"
    [1]=>
    string(9) "Exception"
    [2]=>
    string(14) "ErrorException"
       ... lots of internal classes here ...
    [121]=>
    string(3) "Bar"
    [122]=>
    string(6) "FooBar"
    }
    php >
    

    Example for an interactive mode (using PHP 5.3.18 on Windows)

    PS C:\Users\sven> php -a
    Interactive mode enabled
    
    <?php
    function __autoload($class) { echo "Auto: $class"; eval("class $class {}"); }
    echo "Hello World";
    $x = new Foo;
    var_dump($x);
    var_dump($a = get_declared_classes());
    ^Z
    Hello World
    Fatal error: Class 'Foo' not found in - on line 4
    
    Call Stack:
      100.6337    1114608   1. {main}() -:0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is more of a high-level question than anything else. I have a MVC
This is more of a share knowledge than anything else. Wasn't sure if I
[Caveat] This is not directly a programing question, but it is something that comes
Okay, this is more for my own learning than actual need. I have files
Okay, so this is more of a question that has lots of solutions that
This is more of an hardware question than a software one but still...: I
I am sure this topic has been discussed here before but I would like
I've asked a question similar to this but thought I would ask a more
I'm not asking for personal religious opinions about this philosophy, rather something a bit
This is more of a software engineering question than a programming one. I tried

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.