note 111388 deleted from language.oop5.autoload by crell
| From: | crell@php.net | Date: | Mon, 04 Apr 2022 16:09:50 +0000 |
| Subject: | note 111388 deleted from language.oop5.autoload by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-218024@lists.php.net to get a copy of this message | ||
Note Submitter: tlang at halsoft dot com
----
This page states that autoloading does not work when PHP is used in CLI mode but a simple test seems
to contradict this.
Create a file /tmp/Foo.php containing:
<?php
class Foo {
public function __construct() {
echo "Inside the Foo constructor\n";
}
}
?>
Create a script (NOT in /tmp) containing:
<?php
function test_autoload($class) {
require_once '/tmp/'.$class.'.php';
}
spl_autoload_register('test_autoload');
$foo = new Foo();
?>
Execute the script on the command line. The echo statement in the constructor produces output to
STDOUT.
This also works with __autoload
<?php
function __autoload($class) {
require_once '/tmp/'.$class.'.php';
}
$foo = new Foo();
?>