class class name{
function__autoload($ClassName){
$path=$ClassName.'.php';
if(file_exists($path)){//Judge whether the file exists
, I checked it several times, but I couldn’t see the statement meaning $ClassName =test. So how could he import text.php?
That is, when you create a new test class name, the __autoload method will be executed, and the class name test after your new will be passed into this method as a parameter
When you want to reference a non-existent class in this class, after writing the __autoload method, it will automatically determine whether the class file exists, and if it exists, it will be executed.
require_once($path) refers to the class file
You can add the following code to your file
echo (new Autoload1())->god();
echo (new Autoload1())->name;
and then test.php Write
class Test
{
public $name = 'I am the attribute name in the Test class file';
public function god(){
return 'I am the method god in the Test class file' ()';
}
}
You can see that this Test file is automatically introduced and the value can be successfully output