1improved version :
2<?php
3spl_autoload_register(function($className) {
4 $file = __DIR__ . '\\' . $className . '.php';
5 $file = str_replace('\\', DIRECTORY_SEPARATOR, $file);
6 if (file_exists($file)) {
7 include $file;
8 }
9});
1inside root directory create a autoloader.php file and add the following code :
2------------------------------------------------------------------------------
3<?php
4spl_autoload_register(function($className) {
5 $file = $className . '.php';
6 if (file_exists($file)) {
7 include $file;
8 }
9});
10
11inside your usage file :
12--------------------------
13<?php
14include 'autoload.php';
15
16$circle = new Circle;
17$square = new Square;