9: Load Classes Automatically In OOP PHP | Object Oriented PHP Tutorial | PHP Tutorial | mmtuts

แชร์
ฝัง
  • เผยแพร่เมื่อ 11 ก.พ. 2025
  • In this OOP PHP tutorial I will show how to load classes automatically, as soon as you instantiate a class. This saves us a lot of trouble in regards to having to update out "includes" and links all the time.
    NOTE:
    In this video I say that "_autoload" would get "depreciated", when I meant to say "discouraged".
    depreciated = will get discontinued
    discouraged = is not recommended
    I know there are viewers out there that care a lot about proper phrasing and such, so I thought I'd clarify here :)
    Link to this playlist: • 1: Introduction To OOP...
    ➤ GET ACCESS TO MY LESSON MATERIAL HERE!
    First of all, thank you for all the support you have given me!
    I am really glad to have such an awesome community on my channel. It motivates me to continue creating and uploading content! So thank you!
    I am now using Patreon to share improved and updated lesson material, and for a small fee you can access all the material. I have worked hard, and done my best to help you understand what I teach.
    I hope you will find it helpful :)
    Material for this lesson: / lesson-material-42361704

ความคิดเห็น • 268

  • @Dani_Krossing
    @Dani_Krossing  5 ปีที่แล้ว +81

    NOTE:
    In this video I say that "_autoload" would get "depreciated", when I meant to say "discouraged".
    depreciated = will get discontinued
    discouraged = is not recommended
    I know there are viewers out there that care a lot about proper phrasing and such, so I thought I'd clarify here :)

    • @wren7182
      @wren7182 5 ปีที่แล้ว +3

      Somewhere in Germany you are helping a whole bunch of bachelor students... :)

    • @zaidh41
      @zaidh41 5 ปีที่แล้ว +2

      upload full login system with pdo please...........

    • @pxjesse8128
      @pxjesse8128 5 ปีที่แล้ว

      Hey, I'm having an error where the autoloader can't find the file because it's looking for the capitalized "Person.class.php", while mine is called "person.class.php". Any idea why this is happening for me and not for you in the video? Thanks in advance ;)

    • @davidspooner5021
      @davidspooner5021 5 ปีที่แล้ว +5

      www.php.net/manual/en/function.autoload.php says that __autoload() "has been DEPRECATED as of PHP 7.2.0. "

    • @mrpddnos
      @mrpddnos 5 ปีที่แล้ว +1

      PXJesse the paths are case sensitive. You either need to make spelling of your file names the same as the spelling of your class names or use strtolower() around $className in the myAutoloader() function

  • @bigdoggetom6549
    @bigdoggetom6549 4 ปีที่แล้ว +108

    One thing worth mentioning, if your server is running on Linux, you need to make two adjustments to what Dan has done in the video. Firstly, as Linux (unlike WIndows) is case sensitive, if you are calling your classes with a capital letter (eg. Person, rather than person, like in the video), you need to also make sure your class file is capitalised, eg. Person.class.php. Secondly, if using namespaces, you need to make a change to the autoloader function. As Linux uses forward slashes for file directories, you should add: $fullpath = str_replace('\\', '/', $fullpath); to replace the backslashes picked up with forward slashes. I believe even if you add this line, it will also still work on Windows anyway

    • @ThePancakeJedi
      @ThePancakeJedi 4 ปีที่แล้ว +3

      THANK YOU! I've been looking all over as to what the problem might be. Should've looked in the comment section sooner.

    • @liamkao1653
      @liamkao1653 4 ปีที่แล้ว +4

      thank you! you save me.

    • @hectorluis9294
      @hectorluis9294 3 ปีที่แล้ว +2

      You save my day dude.

    • @karanraiyani3579
      @karanraiyani3579 3 ปีที่แล้ว +2

      Thank you for saving my time

    • @ChadAmI80
      @ChadAmI80 3 ปีที่แล้ว +2

      Thank you! For the life of me I couldn't figure out why when I set the namespace to Person\Person that this was not running when I had my class named Person.class.php I'm running windows using Local from FlyWheel as my "server". This fixed it.

  • @Mesrour
    @Mesrour 11 หลายเดือนก่อน +4

    I can't imagine someone who can teach coding with simple and clear explanations like you. When someone understands the 'WHY', he can explain anything. If not, he will resort to repeating incomprehensible puzzles.

  • @francoisbourvil8733
    @francoisbourvil8733 5 ปีที่แล้ว +19

    I really hope you'll get many more subscribers, because even for someone who already "knows" OOP in PHP, your explanations are very clear and easy to follow.
    You really ease the understanding of that core concept !
    Thanks for these great courses !

  • @mh_reja
    @mh_reja 4 ปีที่แล้ว +4

    I was scaring to get into OOP php, when I was trying to understand it, my brain stopped working. But, you have eased all this, you teach in a very supercallifragilistic way.
    As of now my brain has started working 😆😊 to understand php OOP. Thank you very much.

  • @powpowalemany3990
    @powpowalemany3990 4 ปีที่แล้ว +2

    I am a new to PHP programming and have done too many procedural programming, actually I use procedural programming in our capstone project.
    I've heard a lot in OOP and done some research about OOP and I had a hard time studying OOP until I saw your tutorials about OOP(PHP) it is easier to understand the way you explain things.
    Thank you so much.

  • @tictac1020
    @tictac1020 4 ปีที่แล้ว +1

    I've been coding for something like 6 years now (front end) and there's a handful of areas where my brain never quite clicked. MVC in PHP is one of those areas. I have realized over time that my brain needs the conceptual explanation, the abstract high level overview of things instead of just the explicit instructions on implementation. If I understand the idea of how it's supposed to work, I can figure out the implementation. All this is to say I really love your style of teaching and that you focus on the concept and not just the implementation. Cheers!

  • @marlub
    @marlub หลายเดือนก่อน

    I've just gone through your episode with morning coffee :) A pill of very usefull information for me while learning php. Great tut!

  • @kelvezu1585
    @kelvezu1585 5 ปีที่แล้ว +13

    You're the best PHP teacher. Thanks Dan

  • @richardwilkins5241
    @richardwilkins5241 3 ปีที่แล้ว +3

    This was a great PHP OOP 'good-housekeeping' lesson. Really helpful. Thank you.

  • @brunosastre1317
    @brunosastre1317 3 ปีที่แล้ว +2

    I love how enthusiastically you teach!

  • @juliusmboto7289
    @juliusmboto7289 2 ปีที่แล้ว +3

    I learned a lot from you sir!, but one thing, i follow everything on this video about Load classes Automatically. But for me doesnt work but i tried to find a solution then i came up with
    and it works for me!, so in case anyone facing this issue, please try the suggestion i just provided!
    Anyway big thanks for sharing free resource to the world.

    • @hayatzee8830
      @hayatzee8830 2 ปีที่แล้ว

      Same here, Thank you for the alternative solution.

    • @ngabers3313
      @ngabers3313 4 หลายเดือนก่อน

      your code is more simplier

    • @potatochipappi
      @potatochipappi 2 หลายเดือนก่อน

      You are good thanks, I can’t believe this approach is simpler I even understand this by reading.

  • @mhassan2018
    @mhassan2018 5 ปีที่แล้ว +7

    keep going man i really enjoy each and every single episode you make

  • @robustreviews
    @robustreviews 3 ปีที่แล้ว

    Perfect as ever! For a little bit of finesse in production (and to hide anything useful to a hacker) you can change _return false;_
    to an error handler:
    die("Error - Please try again later");
    or an error code, or whatever works best for your project.

  • @vladiklass1890
    @vladiklass1890 4 ปีที่แล้ว +1

    Thank you so much for explaining it in such an interesting way that I'm watching it instead of Netflix on Sunday afternoon! :D

  • @trishapellis
    @trishapellis 11 หลายเดือนก่อน +1

    I have seen someone else comment this on another video of yours, but here nobody seems to be doing it, so I'll put it here for anyone who gets confused about this in the future (because I did).
    I think it's a consequence of using Linux/Ubuntu or something like that, but the autoloader may fail for no apparent reason. For people who have this problem, try turning the line "$fullPath = $path . $className . $extension;" into "$fullPath = $path . strtolower($className) . $extension;".
    The problem in this case is that the program differentiates between uppercase and lowercase. Since we're obligated to write class filenames in all lowercase, but the class name itself has to be capitalized, the autoloader can't find the file, because it's looking for a capitalized file name. Strtolower makes the $className variable lowercase.

  • @guscostarock
    @guscostarock 2 ปีที่แล้ว +2

    Wow man, you really have the talent to make a hard concept become easy, I appreciate your work and it is helping me a lot.Thanks for that!

  • @robertbajo9474
    @robertbajo9474 5 ปีที่แล้ว +1

    Great! Man your tutorials about coding in PHP are one of the best on youtube!

  • @kristapsvecvagars5049
    @kristapsvecvagars5049 5 ปีที่แล้ว +1

    Love your videos! You just have a way of explaining things so clearly, something that most of my teachers struggled to do, especially with OOP concepts. Thank you for your work and dedication!

  • @mhc4124
    @mhc4124 4 ปีที่แล้ว

    Man, thank you. Best instructing style that I've found out there.

  • @GerritforBazeja
    @GerritforBazeja ปีที่แล้ว

    Thank you for again a nice video in order to learn me OOP!! Never te late to learn or dive into it later on.

  • @andrewcuster6498
    @andrewcuster6498 ปีที่แล้ว

    This lesson is great, and I still have 4 minutes left to watch... Wish I could give two thumbs up, It will really help clean up my code.

  • @syrymzhakypbekov1949
    @syrymzhakypbekov1949 5 ปีที่แล้ว +2

    Great content, and speech delivery is in a very high level, thank you man

  • @markgilsongregorio536
    @markgilsongregorio536 4 ปีที่แล้ว

    I learned a lot from you Sir. Dan, 9 more episodes to go! Thank you so much for the lectures

  • @virusbastion7526
    @virusbastion7526 5 ปีที่แล้ว +1

    You the best out there man... Thank you very much... My college teacher sucks

  • @fredpourlesintimes
    @fredpourlesintimes 5 ปีที่แล้ว

    I didn't learn namespaces yet, but your explanation about classes loading is really great.

  • @FaizulHassan-ek2mw
    @FaizulHassan-ek2mw 4 ปีที่แล้ว

    Beautifully described by a graceful young man.
    Great!

  • @digital_mindmeld
    @digital_mindmeld 2 ปีที่แล้ว

    Nice to mention = that when you implement namespaces on the login system at the end of this course you need backspaces where you extend to dbh in the class root folder and every time you make a pdo call. Either that or you need to add dbh in every folder you use it and add the same namespace to it. (Saved you 30 minutes of figuring that out when u try to combine these two)

  • @wing-views
    @wing-views 3 ปีที่แล้ว

    15:06 That was me. Jumped to 17th chapter. Got an error and watching this video. ;)

  • @JoaoPedro-dx6pn
    @JoaoPedro-dx6pn 3 ปีที่แล้ว

    Ameeeeeen lol finally some good explanation about autoloading. Thanksss

  • @M45963
    @M45963 3 ปีที่แล้ว

    Hi Dani, first of all, thank you so much on the effort you put to do this tutorial, because it's amazing and I can understand everything (I'm new on PHP so this it's really helpful). Additionally I want to make a suggestion about the order of this videos, because it would be great to put before the N°3. "Create Classes in OOP". Regards.

  • @_timestamp
    @_timestamp 5 ปีที่แล้ว

    Best php channel. Good job Daniel, good job

  • @lmagalhaeslopes
    @lmagalhaeslopes 4 ปีที่แล้ว

    Dude, fantastic explanation, you are a beast, congratulations

  • @MuhammadAli-sl9qd
    @MuhammadAli-sl9qd 5 ปีที่แล้ว +12

    spl_autoload_register('classLoader');
    function classLoader($class){
    $path = "classes/".$class.".class.php";
    include_once $path;
    }
    this will also work.

    • @usamawarraich339
      @usamawarraich339 4 ปีที่แล้ว

      Thanks man :)

    • @DeshantaDevkota
      @DeshantaDevkota 3 ปีที่แล้ว

      spl_autoload_register(function($className){
      include_once "classes/".$className.".class.php";});

  • @techortrick3012
    @techortrick3012 2 ปีที่แล้ว

    Thanks. Great teacher. Better than my college lecturar

  • @rafaelmartineztomas4911
    @rafaelmartineztomas4911 3 ปีที่แล้ว

    Thanks for the videos bro !! Have a good day!

  • @Alex_Heil
    @Alex_Heil 4 ปีที่แล้ว +2

    if you’re having problems with the autoloader and namespaces this might help:
    change the $fullPath variable inside the myAutoLoader function to this:
    $fullPath = $path . str_replace('\\', '/', $className) . $extension;
    full code in autoloader.inc.php:
    spl_autoload_register("myAutoLoader");
    function myAutoLoader($className) {
    $path = "classes/";
    $extension = ".class.php";
    $fullPath = $path . str_replace('\\', '/', $className) . $extension;
    if (!file_exists($fullPath)) {
    return false;
    }
    include_once $fullPath;
    }
    hope this helps ;)

    • @muzika5001
      @muzika5001 3 ปีที่แล้ว

      Omg, Alex! Thank you very much! You saved the night and headache! :)

    • @BneiAnusim
      @BneiAnusim 2 ปีที่แล้ว

      $fullPath = $path . str_replace('\\', '/', $className) . $extension; fixed my issue. Thank you very much!

    • @sumanbd77
      @sumanbd77 ปีที่แล้ว

      Alex Heil Thank you so much.

    • @sumanbd77
      @sumanbd77 ปีที่แล้ว

      Same from myside also.

  • @fullstackgreekdeveloper8033
    @fullstackgreekdeveloper8033 4 ปีที่แล้ว +3

    For php 7.4 just add this line between $extension and $fullPath variable declarations :
    $className = str_replace("\\", DIRECTORY_SEPARATOR, $className);

  • @electronicheartbreak.
    @electronicheartbreak. 5 ปีที่แล้ว

    I am probably that early that the video isn't fully rendered to 720p quality :). Another nice tutorial.

  • @warzhenaji6380
    @warzhenaji6380 5 ปีที่แล้ว

    At 8:21 on lines 2-10, would it be wrong to place the function [spl_autoload_register('myautoloader')] AFTER the bit from line 4 to line 9? Would it ruin the logic, or would it run the same? Also, thanks Daniel. You're a life saver. This is the only coding tutorial resource that anyone should use on TH-cam.

  • @pixandcodes6333
    @pixandcodes6333 4 ปีที่แล้ว

    I love all of your videos.

  • @ayatohigashi5113
    @ayatohigashi5113 4 ปีที่แล้ว

    Thanks for all this wonderful videos.
    You are awesome!!!!!

  • @islamsaied6484
    @islamsaied6484 5 ปีที่แล้ว

    one of the best i have ever seen god bless you

  • @The-Great-Brindian
    @The-Great-Brindian 3 ปีที่แล้ว

    Dani, put a book out. IF you have the time/energy that is. I know everything is 'digital' these days but trust me, there are some 'old-schoolers' like myself who still love a good 'Programming book' to read.
    Some of the best sources still are books, believe it or not.

  • @halim6150
    @halim6150 5 ปีที่แล้ว

    Thank you man, you put it very simply.

  • @ademineshat
    @ademineshat 5 ปีที่แล้ว +1

    Video quality?!
    Anyway, best video so far :)

  • @ali-pc7nv
    @ali-pc7nv 7 หลายเดือนก่อน

    Brilliant as always

  • @poovarasimurthy6852
    @poovarasimurthy6852 4 ปีที่แล้ว +1

    your way of explanation is too cool and i can understand it clearly.
    I have a question to ask
    how can we call the inheritance child class name by this auto loader function
    thanks in advance!!!

  • @zoynuldotcom
    @zoynuldotcom 3 ปีที่แล้ว

    Thank you brother, Great tutorial

  • @collectorX
    @collectorX ปีที่แล้ว

    Thank u so much for the work.. that helps us a lot

  • @SNikhill
    @SNikhill 5 ปีที่แล้ว

    Your tutorials are just awesome. :)

  • @germanduterte7110
    @germanduterte7110 5 ปีที่แล้ว

    Very clear explanation, thanks a lot

  • @xanduong7780
    @xanduong7780 4 ปีที่แล้ว

    thank you man. you save my life;

  • @patrickbroaden9820
    @patrickbroaden9820 4 ปีที่แล้ว

    Informative, usual....👍🏾

  • @johwel340
    @johwel340 5 ปีที่แล้ว +65

    Elon Musk looks like you or you look like Elon Musk :-D

    • @dfordemo981
      @dfordemo981 4 ปีที่แล้ว

      hehe same comment as i did in first video,

  • @isaiahdaniel2522
    @isaiahdaniel2522 5 ปีที่แล้ว

    Really love the new view, thanks Daniel

  • @hamzaarshad9690
    @hamzaarshad9690 5 ปีที่แล้ว +6

    I was having problem in executing the code than I changed the name of my file containing the Class "Person" to Person.class.php and then the code started working. I don't know this will work in future or not but it is working for now

    • @DawoopFilms
      @DawoopFilms 5 ปีที่แล้ว +4

      Oh thank you, I was having the same problem... was about to throw my pc through the window

    • @raylee141414
      @raylee141414 5 ปีที่แล้ว

      @@DawoopFilms I have the same problem too, threw my pc through the window, just take back

    • @raylee141414
      @raylee141414 5 ปีที่แล้ว

      btw, i found that the Person in the path actually follows that word when i call the class person1 = new Person in index.php

  • @hamzaarshad9690
    @hamzaarshad9690 5 ปีที่แล้ว +3

    Namespace sometime doesn't work if you leave any space before the php start tag "

  • @pythonsamurai
    @pythonsamurai 4 ปีที่แล้ว

    I love this lector, thank you!

  • @chitrajha7575
    @chitrajha7575 5 ปีที่แล้ว

    You are a osammm teacher , Thank you so much for your videos

  • @sherkan_n
    @sherkan_n 5 ปีที่แล้ว

    I like your videos, i learn many of them.

  • @Cortexikid
    @Cortexikid 5 ปีที่แล้ว +2

    Hi! Your video courses are so useful, I have already learned a lot from you, so thank you for your work!
    I have a question about the 'myAutoLoader' method, though. Kind of evident what is happening, there is only one part I couldn't comprehend, how does it know what the '$className' is? When do we give that parameter to the method? Thank you for the answer in advance! :)

  • @AsimYilan
    @AsimYilan 7 หลายเดือนก่อน

    thank u dude u rescure my life :D

  • @fnp1999
    @fnp1999 3 ปีที่แล้ว

    Very good class my friend.

  • @stephenchen54
    @stephenchen54 5 ปีที่แล้ว +3

    Hi, I am wondering are we supposed to set the file name as "Person.class.php" (with a capitalized "P" instead of a lower case "p"). When I use the "person.class.php" I got an error, while when it comes to "Person.class.php", the error disappeared. Thanks.

    • @pxjesse8128
      @pxjesse8128 5 ปีที่แล้ว +1

      To use the same capitalization as in the video, I added $className = strtolower($className); in front of the $fullPath variable in the autoloader. It's more of a workaround than it is a solution, but it's a start

    • @mrpddnos
      @mrpddnos 5 ปีที่แล้ว +1

      the paths are case sensitive. You either need to make spelling of your file names the same as the spelling of your class names or use strtolower() around $className in the myAutoloader() function.
      Example:
      $fullPath = $path . strtolower($className) . $extension;
      The best solution is consistent file naming. File names are recommended to be lower class. So it’s advisable to use the code in my example. Somehow you need to change the uppercase letters in the class name to lowercase in the file name. The example is how you do that.

    • @iulian1234566
      @iulian1234566 4 ปีที่แล้ว +1

      for Windows - add strtolower($className) - because he named the file person.class.php and the class in it is Person.
      spl_autoload_register('myAutoLoader');
      function myAutoLoader($className) {
      $path = "classes/";
      $extension = ".class.php";
      $fullPath = $path . strtolower($className) . $extension;
      if (!file_exists($fullPath)) {
      return false;
      }
      include_once $fullPath;
      }

  • @mlawalkthrough
    @mlawalkthrough 5 ปีที่แล้ว

    Thank you. Please more advanced php oop lessons.

  • @ForeverXDful
    @ForeverXDful 4 ปีที่แล้ว

    your videos are the best. can you take a video about Composer?? It would be great.

  • @dgloria
    @dgloria ปีที่แล้ว

    Hi Dani, how does the spl_autoload_register knows which files to load? I don't see the Person/House explicitly passed on, or a foreach for every file in the repo. Thank you

  • @pragneshkatkar31
    @pragneshkatkar31 5 ปีที่แล้ว +1

    Hello Daniel, can you please discuss about navigation and routing?

  • @uniqcoda
    @uniqcoda 4 ปีที่แล้ว

    It messed with my head too much 😁😁 I had to watch it twice to understand. BTW, I like the way you teach but I don't know your name...

  • @isaachatilima
    @isaachatilima 5 ปีที่แล้ว +1

    Great tutorials. When are you going to do Laravel?

  • @deepgagan9015
    @deepgagan9015 5 ปีที่แล้ว +1

    Hello sir,
    Thank you so much for the valuable tutorials.
    I used this autoloader function in my project.
    It was working perfectly on local host.
    but when I uploaded my project on godaddy online hosting.
    It is showing me fatal error like this file are not found in autoloader.php file.
    Why i am having this issue on hosting not on local host??
    Thanks in advance

  • @florianprock
    @florianprock 5 ปีที่แล้ว

    Hey, i really liked watching your PHP-OOP Playlist.
    I only want to draw attention to the file naming for your classes.
    I have noticed that upper and lower case letters play an important role in the files and class names.
    Since i have a good basic knowledge about operating systems i can tell you that linux distinguishes between upper and lower case, which is not done in windows.
    There's also an comment, that refers to this issue, so i clarify.
    Thanx for this nice Playlist - keep on making n1ce vidz :)

  • @mohammedissam3651
    @mohammedissam3651 4 ปีที่แล้ว

    Man ur a life saver.

  • @achrafjammoussi8374
    @achrafjammoussi8374 3 ปีที่แล้ว

    that is amazing ! thanks a lot

  • @a-ezzat5677
    @a-ezzat5677 3 ปีที่แล้ว

    what if my class has constructor arguments . how would spl_autoload works, am i have to play a trick with optional args within the function either

  • @phil8899
    @phil8899 5 ปีที่แล้ว +1

    Is it safe to include all the classes? Does it slow down performance or anything?

  • @SureshBhardwaj
    @SureshBhardwaj 4 ปีที่แล้ว

    Thats great Dani! Just wanted to check how secure it is. Can a hacker break into the web server If I enable auto loading feature?

  • @mmohamedbadr
    @mmohamedbadr 2 ปีที่แล้ว

    Perfect ,Thank You

  • @edumaba
    @edumaba ปีที่แล้ว

    Hi Dani, thanks for this awesome tutorial.
    For my autoloader code to work I had to convert the $className variable to lower case for it to work. Another way was to rename the person class file to "Person.inc.php".
    Yours worked without doing that, how?

  • @gololacharles3110
    @gololacharles3110 4 ปีที่แล้ว +1

    Dear mmtuts, I used this tutorial and included the automatic loading of classes to my Project, It worked fine on the localhost, Unfortunately its failing after moving the project to an online server.
    Kindly advise me.
    Thanks

    • @ApplicableProgramming
      @ApplicableProgramming 4 ปีที่แล้ว

      I assume your online server is linux and you are developing on windows? Check if files are capitalised properly, as on linux MyClass.php is not the same file as Myclass.php (not the capital C)

  • @johnnguyen1655
    @johnnguyen1655 5 ปีที่แล้ว +2

    I wonder where and how to pass value to the $className variable in autoloader. in the video the actual value is 'class' but how PHP to understand that. Let say we name files with something like somename.notclass.php, does it work?

    • @kvazaios5026
      @kvazaios5026 4 ปีที่แล้ว

      yoooo thats what I was thinking about, its like magic

    • @Kallas13
      @Kallas13 4 ปีที่แล้ว

      when the myAutoLoader method is called it actually uses the word you typed when you instantiated the object. so let's say it is $person1 = new Person(); , it will use "Person" as $className. You can see this by echoing $fullPath or by having the filename be different than the class name, causing an error. He did briefly show this when he changed Person in the index.php file to Persond.

  • @lifeslittleescapes
    @lifeslittleescapes 4 ปีที่แล้ว

    Nice ending...for those who jumps at the middle and confuse all...😂😂😂

  • @patrikTHELEGEND
    @patrikTHELEGEND 5 ปีที่แล้ว +1

    REMEMBER: If you call on static method or property (the ones where you dont need to initialize class) , instead of " new Person\Person " , simply put "Person\Person"

  • @sinankayapinar
    @sinankayapinar 2 ปีที่แล้ว +2

    If you use namespace, your autoloader.inc.php page must be so:
    spl_autoload_register('myAutoLoader');
    function myAutoLoader($className)
    {
    $path = "classes/";
    $extention = ".class.php";
    $fullPath = $path . $className . $extention;
    $fullPath=str_replace("\\","/",$fullPath);
    if (!file_exists($fullPath)) {
    echo $fullPath;
    }
    include_once $fullPath;
    }

    • @lalityadav536
      @lalityadav536 ปีที่แล้ว +1

      You are right Sinan by adding the statement $fullPath=str_replace("\\","/",$fullPath); removes the error "Fatal error: Uncaught Error: Class "Person\Person" not found in /var/www/html/". This error was occurring while I was using namespace in the person class.

    • @dirkrobbertse4503
      @dirkrobbertse4503 ปีที่แล้ว +1

      Thank you for adding this i was trying to figure it out...

  • @adeyemiadeshina3988
    @adeyemiadeshina3988 4 ปีที่แล้ว

    Thank you Dani!

  • @prashanthkumar0
    @prashanthkumar0 5 ปีที่แล้ว

    great 👍💗💗
    please continue php

  • @brinishbritto5781
    @brinishbritto5781 4 ปีที่แล้ว +1

    If u r still facing the issue, then do this :
    inside classes/include.class.php
    spl_autoload_register('myAutoloader');
    function myAutoloader($className) {
    include_once(dirname(__FILE__) . '/'. strtolower($className). '.class.php';
    }

  • @theobellash6440
    @theobellash6440 2 ปีที่แล้ว +1

    05:00 When is that future though??? One still use it

  • @Lyrik-Klinge
    @Lyrik-Klinge ปีที่แล้ว

    That's it, THANKS!

  • @Rii-Americano
    @Rii-Americano 5 ปีที่แล้ว

    I love your tutorial

  • @EdMartinModesto
    @EdMartinModesto 5 ปีที่แล้ว

    I am getting several errors that seem to indicate a path issue. I also get Undefine variable: classname when I moved the autoloader.inc.php file into the includes folder. I have tried some of the solutions listed in the comments with no luck.

  • @seunalegbeleye2746
    @seunalegbeleye2746 5 ปีที่แล้ว

    Hi mmtuts, I recently worked on fintech project in which several of your videos empowered me to do it. But i have a question: I noticed that in some fin-tech websites, when you view their page source to check the front end code, you won't see the value of the form's action e.g=> action=" "-- but in my own project it appears. I think not appearing is a good security measure. Please how can i make my form' action value not to show when someone view its page source.

  • @محمدحمدي-و7ح7ح
    @محمدحمدي-و7ح7ح 11 หลายเดือนก่อน

    thsnks a lot Dani

  • @iqbaldhillon175
    @iqbaldhillon175 5 ปีที่แล้ว

    i have class file in classes folder.but in that class file i have defined multiple classes.how to access data from them??

  • @MHdeJong87
    @MHdeJong87 5 ปีที่แล้ว +1

    really nice tutorial! thank you so much! One question about something I not totally understand:
    In autoloader.inc.php you only "open" the php script with "" ?

    • @mrpddnos
      @mrpddnos 5 ปีที่แล้ว +2

      You only have to close php in a file where you use php along side something else (like html). When a file is purely php the php interpreter closes php automatically. No need to do it yourself.

  • @UTUVines
    @UTUVines 5 ปีที่แล้ว

    Hey i have one doubt
    am making one course website in php. and mysqli.
    i want make course as a paid course.
    i desinged everthing.
    frontend and backend is almost done.
    but
    example :- when a person is coming on website to buy a course
    first person login and then person pays the amount of course.
    and after that he gets that course infact (the course get unlock on that specific id)
    can you please tell me how this lock and unlock happens.
    MEANS
    how the course is getting unlocked after paying the amount.
    can you please tell me the PHP or else else logic behind that

  • @ThatoJChere
    @ThatoJChere 4 ปีที่แล้ว

    i used autoload in my project, now after loginIn, my autoload function is no longer recognizable... Where should i require this file so it can be visible to all pages or i have to include/require it on all other files? Thanks in Advance...

  • @noiononfiniscosennoquestid6810
    @noiononfiniscosennoquestid6810 5 ปีที่แล้ว +1

    Login system using PDO?

  • @bjornarmar2462
    @bjornarmar2462 5 ปีที่แล้ว

    I don't understand how *$className* gets automatically assigned when a class is used to instantiate an object.
    Is this simply something that the *spl_autoload_register()* function somehow does under the hood once it identifies a class that has been instantiated?