PHP Conference Japan 2021 Online

Voting

Please answer this simple SPAM challenge: one minus zero?
(Example: nine)

The Note You're Voting On

tlang at halsoft dot com
8 years ago
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();
?>

<< Back to user notes page

To Top