I am trying autoload function in php. The files are all in the same directory. I have a file called aviation.php with the following code:
class Avaitor{
public function __construct(){
echo "Fly high<br>";
}
}
Then in my autoloader file I am trying to do this:
function __autoload($fileName){
if(file_exists($fileName . ".php"))
require_once $fileName . ".php";
}
//require_once "aviatior.php";
$pilot = new Avaitor();
But I am getting this error:
Fatal error: Uncaught Error: Class 'Avaitor' not found in /Applications/MAMP/htdocs/php_oop/autoload.php:22 Stack trace: #0 {main} thrown in /Applications/MAMP/htdocs/php_oop/autoload.php on line 22
Just to test that require_once does find my aviator.php I tried it out and then commented it out.
What am I doing wrong here?