note 111388 added to language.oop5.autoload
| From: | tlang at halsoft dot com | Date: | Thu, 14 Feb 2013 21:56:50 +0000 |
| Subject: | note 111388 added to language.oop5.autoload | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-193639@lists.php.net to get a copy of this message | ||
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();
?>
----
Server IP: 69.147.83.199
Probable Submitter: 199.58.143.46
----
Manual Page -- http://php.net/manual/en/language.oop5.autoload.php
Edit -- https://master.php.net/note/edit/111388
Del: integrated -- https://master.php.net/note/delete/111388/integrated
Del: useless -- https://master.php.net/note/delete/111388/useless
Del: bad code -- https://master.php.net/note/delete/111388/bad+code
Del: spam -- https://master.php.net/note/delete/111388/spam
Del: non-english -- https://master.php.net/note/delete/111388/non-english
Del: in docs -- https://master.php.net/note/delete/111388/in+docs
Del: other reasons-- https://master.php.net/note/delete/111388
Reject -- https://master.php.net/note/reject/111388
Search -- https://master.php.net/manage/user-notes.php