php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #40775 __autoload not invoked in cli interactive mode?
Submitted: 2007-03-11 12:20 UTC Modified: 2007-05-14 10:02 UTC
From: seanius at debian dot org Assigned: rquadling (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.2.1 OS: Debian GNU/Linux
Private report: No CVE-ID: None
 [2007-03-11 12:20 UTC] seanius at debian dot org
Description:
------------
the __autoload hook doesn't seem to be run for the cmdline/cgi versions  of php when invoked in "interactive" (-a) mode.

originally reported at http://bugs.debian.org/406264

Reproduce code:
---------------
<?php
function __autoload($class)
{
echo $class;// should output class name
echo 'lol';// should at least print it if it comes into function body
require($class . '.php');// should break script because of missing file
}
// but it will just cause fatal error about missing class :|
$foo = new Bar(); ?>

Expected result:
----------------
client-158[~]13:14:49$ php < foo.php
Barlol
Warning: require(Bar.php): failed to open stream: No such file or directory in - on line 6

Fatal error: require(): Failed opening required 'Bar.php' (include_path='.:/usr/share/php:/usr/share/pear') in - on line 6



Actual result:
--------------
client-158[~]13:14:54$ php -a < foo.php
Interactive mode enabled


Fatal error: Class 'Bar' not found in - on line 9

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-04-26 09:16 UTC] tony2001@php.net
Yes, __autoload() can not be invoked when compiling because compiler is not reentrant (and interactive mode means we're always compiling).
Reclassified as docu problem.
 [2007-05-14 09:54 UTC] rquadling@php.net
The manual stages that using auto_prepend_file/auto_append_file are allowed in interactive mode:

"Files included through auto_prepend_file and auto_append_file are parsed in this mode but with some restrictions - e.g. functions have to be defined before called."

So, I have an __autoload() function in a file which is included in my auto_prepend_file entry.

php -a
<?php
echo ini_get('auto_prepend_file'), PHP_EOL, function_exists('__autoload') ? 'Found loader' : 'No loader', PHP_EOL;
$obj_DB = new class_DB();
?>

results in 

2007/05/14 10:51:34 C:\>php -a
Interactive mode enabled

<?php
echo ini_get('auto_prepend_file'), PHP_EOL, function_exists('__autoload') ? 'Found loader' : 'No loader', PHP_EOL;
auto_loader.php
Found loader
$obj_DB = new class_DB();

Fatal error: Class 'class_DB' not found in C:\- on line 3

2007/05/14 10:51:35 C:\>?>
The syntax of the command is incorrect.

2007/05/14 10:51:35 C:\>

So.

I'll document this in the "Autoloading objects" page and in "-a"/interactive shell page.
 [2007-05-14 10:02 UTC] rquadling@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 [2020-02-07 06:10 UTC] phpdocbot@php.net
Automatic comment on behalf of rquadling
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=2e1e467bdf30514c916269c82e5a0568bfd2f0e6
Log: FIX #40775 : PHP -a and __autoload() don't mix.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Jul 31 01:01:23 2021 UTC