- spl_autoload_register: documentation ( source)
<?php
$code = <<<EOB
trait my_trait {
static function test(\$arg) { echo \$arg; }
}
EOB;
function my_autoloader($class) {
global $code;
echo "autoloading $class\n";
eval($code);
}
spl_autoload_register('my_autoloader');
class try_it {
use my_trait;
}
try_it::test("does it work?\n");