是否有一种方法我可以在类中定义
<?php
class Test {
public function __construct() {
echo Instantiating , __CLASS__, "
";
}
public function __autoload($className) {
echo "Loading $className
";
require_once($className . .php );
}
public function test() {
$test = new AnotherClass();
}
}
$bill = new Test();
$bill->test();
另一类. php:
<?php
class AnotherClass {
public function __construct() {
echo Instantiating , __CLASS__, "
";
}
}
产出:
Instantiating Test Loading AnotherClass Instantiating AnotherClass