1.
<?php
$name = 'abc';
require "{$name}.php";
$class = new $name();
注意你的类名和文件名要一致
CentOS 9
2.
@xxb,感谢,已经成功
并放上最终代码,以供后人参考
------------
index.php
<?php
$a = 't';
require $a.'.php';
$$a = new $a();
print_r($t);
---
t.php
<?php
class t
{
function __CONSTRUCT()
{
$this -> a = "test";
}
function test()
{
echo 'ok';
}
}
echo "file required";
---
运行结果
file requiredt Object ( [a] => test )
3.
用自动加载不香吗?
白日梦还是要做的, 万一实现了呢?