php __autoload function

3 comments


__autoload(string $className) — Attempt to load undefined class

This autoload function call when we will try to create instance of undefined class.
Like here we don’t have class A in index.php. If in index.php file we don’t have __autoload function
We will can get error. But because of this function we can load file for class A


index.php
<?phpfunction __autoload($className){    $filename = "./". $className .".php";    include_once($filename);}

$obj = new A();?>


A.php
<?php class A { public function __construct() { echo "TEST"; return $this } }?>


3 comments:

  1. I have too much difficulty to load file but because of this article I can easily load file.
    This is very very help to me in my project.
    Thank you very much for this article.

    ReplyDelete
  2. yes its very helpful article

    ReplyDelete