OOP PHP | Autoload Class #18

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] welcome back to earth series for PHP and in this episode we are going to learn about the auto loading so firstly let's check out this interface folder we have created when we have learned about the interface and in the shapes dot PHP folder we have this triangle class in which I have the get area class and get circumference class is just not going to calculate the area but just for the demonstration and then I am creating the object of this triangle class and then just echoing out the area so if I go to Chrome and say interface slash shape dot PHP and you will see triangle area is here which is here but for working of all these things we need to include these two files so if I uncomment this and go here reload yeah we are getting the error so obviously we have conclude that's not a big deal but suppose you have a large project and you need to implement one hundred and hundreds of these include file and obviously this is not the one page in the every pitch you have to include the files so it will be all tedious and one important thing that if you ever change only one file then you have to change that file name in the every file wherever you are including it so PHP gives you an awesome thing called Auto loading system so instead of these two what I am doing I am going to include only one file include and that file name is let's say it auto load dot PHP simple so now let's create that file so I will say or to load dot PHP PHP tag here I will say SPL is still extent for standard PHP library okay then SPL underscore autoload underscore register and it's just like a magic you will see here I will give a function okay and in this function I will give the class okay and for now just see what this class will do so I will say echo this class and that's it okay so let's open Chrome reload and yeah we are getting error but at the top you can see it says shape interface actually this is where we are having system whenever we are using any file any class which we have to include then this autoloader file will get that class name here and here it's echoing out so we are echoing this shape interface okay so now what I will do I will just say include and whatever the class then concatenate with dot PHP file extension okay so reload and yeah it's working but there is one problem suppose my file name is having different so instead of shape interface I have shapes interface let's see what happened now oh it's now giving another problem it says something that even the autoloader doesn't resolve this thing so for that what we have to do we have to go here and firstly we have to check whether if it is available or not so I will say if the file underscore exists and if the file exists then we have to give the file name so why not create a variable which is loading the file names of file name is equal to dollar class then concatenate with dot PHP and here I will say dollar filename so if this not exist then just return false otherwise include this file name so file name okay so go reload and yeah it's now saying the same error which is obviously the normal error which says ships interface not found okay but if now I go and change that reload and yes it's working properly so this is the autoloading system where you don't have to do anything just include this and you don't have to include each and every file in your project okay so this is very nice but in the next episode we will see the problem with this Auto loading system and beyond Auto loading what is this so if you have any doubt feel free to message me comment and don't forget to like subscribe and share and also you can like bit films on Facebook Twitter and Instagram so we will meet in the next episode till then the right
Info
Channel: Bitfumes
Views: 19,852
Rating: undefined out of 5
Keywords: php oop, oop php, object oriented programming, object oriented programming php, php object oriented programming, oops in php, php oops, why we need oop, what is oop, what is object, oop object, autoload, autoload php, autoload oop, autoload class, php autoload, oop autoload, autoload php class, class autoload
Id: UvN5pDof1ig
Channel Id: undefined
Length: 5min 36sec (336 seconds)
Published: Sun Aug 20 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.