Thanks ! yeah i saw people say __autoload is depreciated and stuff and spl_autoload or spl_autoload_register is the one to be used , but , i'll slowly graduate into all of that , my aim of leaning autoload was to have a basic idea of how composer etc works , i still have a scrambled brain about all this , but anyways , i even build my own custom programe so i could understand autoload :
https://github.com/gautamz07/autoload
BTW , checkout my index page , it has the following code :
Code: Select all
<?php
function __autoload($class_name)
{
require_once ("$class_name.".'php');
}
$temp = new vehicle();
echo "<br>";
$temp_car = new car();
echo "<br>";
$temp_bus = new bus();
?>
now if i go the the car.php file and rename the class car to carr ,
an error is thrown in my index.php file , which brings me to the following conclusion :
when i say the following line :
the autoload function is called
Code: Select all
function __autoload($class_name)
{
require_once ("$class_name.".'php');
}
now since i have changed the name of the class car to carr , but still kept the file name car.php ,
autoload will throw an error because i am guessing its actually checking for a file name called carr.php , which does exist .
so my conclusion is :
The file name has to be the same as the class name . am i wrong ?