Small questions about the automatic loading of Dugu Jiujian class __autoload()
葫芦娃平衡盘
葫芦娃平衡盘 2017-08-09 00:06:19
0
2
1090

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?

葫芦娃平衡盘
葫芦娃平衡盘

reply all (2)
听装雪碧

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


      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!