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

Поділитися
Вставка
  • Опубліковано 8 лис 2024

КОМЕНТАРІ • 266

  • @Dani_Krossing
    @Dani_Krossing  5 років тому +82

    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 роки тому +107

    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 3 роки тому +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.

  • @wadiibounenni4848
    @wadiibounenni4848 8 місяців тому +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 років тому +20

    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 роки тому +3

    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.

  • @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!

  • @powpowalemany3990
    @powpowalemany3990 4 роки тому +1

    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.

  • @brunosastre1317
    @brunosastre1317 2 роки тому +2

    I love how enthusiastically you teach!

  • @kelvezu1585
    @kelvezu1585 5 років тому +13

    You're the best PHP teacher. Thanks Dan

  • @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.

  • @richardwilkins5241
    @richardwilkins5241 2 роки тому +3

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

  • @juliusmboto7289
    @juliusmboto7289 2 роки тому +2

    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 Місяць тому

      your code is more simplier

  • @mhassan2018
    @mhassan2018 5 років тому +7

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

  • @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!

  • @MuhammadAli-sl9qd
    @MuhammadAli-sl9qd 4 роки тому +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 :)

    • @deshantdevkota2563
      @deshantdevkota2563 3 роки тому

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

  • @trishapellis
    @trishapellis 8 місяців тому

    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.

  • @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!

  • @robertbajo9474
    @robertbajo9474 5 років тому +1

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

  • @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

  • @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.

  • @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)

  • @fullstackgreekdeveloper8033
    @fullstackgreekdeveloper8033 4 роки тому +3

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

  • @fredpourlesintimes
    @fredpourlesintimes 4 роки тому

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

  • @FaizulHassan-ek2mw
    @FaizulHassan-ek2mw 3 роки тому

    Beautifully described by a graceful young man.
    Great!

  • @mhc4124
    @mhc4124 4 роки тому

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

  • @syrymzhakypbekov1949
    @syrymzhakypbekov1949 5 років тому +2

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

  • @markgilsongregorio536
    @markgilsongregorio536 3 роки тому

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

  • @virusbastion7526
    @virusbastion7526 4 роки тому +1

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

  • @GerritforBazeja
    @GerritforBazeja 10 місяців тому

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

  • @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.

  • @johwel340
    @johwel340 5 років тому +65

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

    • @dfordemo981
      @dfordemo981 3 роки тому

      hehe same comment as i did in first video,

  • @_timestamp
    @_timestamp 5 років тому

    Best php channel. Good job Daniel, good job

  • @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!!!

  • @techortrick3012
    @techortrick3012 2 роки тому

    Thanks. Great teacher. Better than my college lecturar

  • @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 2 роки тому

      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.

  • @lmagalhaeslopes
    @lmagalhaeslopes 4 роки тому

    Dude, fantastic explanation, you are a beast, congratulations

  • @electronicheartbreak.
    @electronicheartbreak. 5 років тому

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

  • @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! :)

  • @JoaoPedro-dx6pn
    @JoaoPedro-dx6pn 3 роки тому

    Ameeeeeen lol finally some good explanation about autoloading. Thanksss

  • @pragneshkatkar31
    @pragneshkatkar31 5 років тому +1

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

  • @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 UA-cam.

  • @ademineshat
    @ademineshat 5 років тому +1

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

  • @wing-views
    @wing-views 3 роки тому

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

  • @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';
    }

  • @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.

  • @islamsaied6484
    @islamsaied6484 4 роки тому

    one of the best i have ever seen god bless you

  • @pixandcodes6333
    @pixandcodes6333 4 роки тому

    I love all of your videos.

  • @isaachatilima
    @isaachatilima 5 років тому +1

    Great tutorials. When are you going to do Laravel?

  • @rafaelmartineztomas4911
    @rafaelmartineztomas4911 3 роки тому

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

  • @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"

  • @ali-pc7nv
    @ali-pc7nv 4 місяці тому

    Brilliant as always

  • @germanduterte7110
    @germanduterte7110 5 років тому

    Very clear explanation, thanks a lot

  • @halim6150
    @halim6150 5 років тому

    Thank you man, you put it very simply.

  • @zoynuldotcom
    @zoynuldotcom 3 роки тому

    Thank you brother, Great tutorial

  • @SNikhill
    @SNikhill 5 років тому

    Your tutorials are just awesome. :)

  • @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?

  • @isaiahdaniel2522
    @isaiahdaniel2522 5 років тому

    Really love the new view, thanks Daniel

  • @xanduong7780
    @xanduong7780 4 роки тому

    thank you man. you save my life;

  • @collectorX
    @collectorX Рік тому

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

  • @mlawalkthrough
    @mlawalkthrough 5 років тому

    Thank you. Please more advanced php oop lessons.

  • @Lyrik-Klinge
    @Lyrik-Klinge Рік тому

    That's it, THANKS!

  • @patrickbroaden9820
    @patrickbroaden9820 4 роки тому

    Informative, usual....👍🏾

  • @mmohamedbadr
    @mmohamedbadr 2 роки тому

    Perfect ,Thank You

  • @hamzaarshad9690
    @hamzaarshad9690 5 років тому +3

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

  • @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.

  • @lifeslittleescapes
    @lifeslittleescapes 4 роки тому

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

  • @ayatohigashi5113
    @ayatohigashi5113 3 роки тому

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

  • @ForeverXDful
    @ForeverXDful 4 роки тому

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

  • @chitrajha7575
    @chitrajha7575 4 роки тому

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

  • @mohammedissam3651
    @mohammedissam3651 4 роки тому

    Man ur a life saver.

  • @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 4 роки тому

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

    • @raylee141414
      @raylee141414 4 роки тому

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

  • @marcelomiranda9623
    @marcelomiranda9623 3 роки тому

    Very good class my friend.

  • @pythonsamurai
    @pythonsamurai 4 роки тому

    I love this lector, thank you!

  • @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;
      }

  • @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?

  • @sherkan_n
    @sherkan_n 5 років тому

    I like your videos, i learn many of them.

  • @achrafjammoussi8374
    @achrafjammoussi8374 3 роки тому

    that is amazing ! thanks a lot

  • @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...

  • @deepgagan9015
    @deepgagan9015 4 роки тому +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

  • @phil8899
    @phil8899 4 роки тому +1

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

  • @adeyemiadeshina3988
    @adeyemiadeshina3988 4 роки тому

    Thank you Dani!

  • @AsimYilan
    @AsimYilan 3 місяці тому

    thank u dude u rescure my life :D

  • @prashanthkumar0
    @prashanthkumar0 5 років тому

    great 👍💗💗
    please continue php

  • @sinankayapinar
    @sinankayapinar Рік тому +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...

  • @Rii-Americano
    @Rii-Americano 5 років тому

    I love your tutorial

  • @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)

  • @محمدحمدي-و7ح7ح
    @محمدحمدي-و7ح7ح 8 місяців тому

    thsnks a lot Dani

  • @bilalbeny4172
    @bilalbeny4172 9 місяців тому

    so powerful video

  • @pbdaemon
    @pbdaemon 5 років тому

    hi your next videos contains register and login with pdo?

  • @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.

  • @nareshramini1796
    @nareshramini1796 5 років тому

    I'm your active follower, I have few doubts with respect to this episode, could you please clear ??
    1Q.) I really didn't understand how those classes are being pulled to feed into that user-defined autoload() function as parameters to create the associated path to be then called in pre defined auto load function that register the full path of classes directory and class file path!
    2Q.) And I didn't understand necessity of name space directory to place the person class file inside it and blah blah blah, something is really not making sense to me at this point!

    • @ajricherson1099
      @ajricherson1099 5 років тому

      I know this is old, but if anyone else is curious:
      1A) I'm not sure if I understand what you mean by "pulled to feed" the function, but I think you are asking how the function is called, and how the class is passed in as a parameter. This isn't a super simple question to answer, but basically spl_autoload_register is doing some magic under the hood, and automatically calling the function that was passed into it as a parameter. You don't really need to worry about how at this point.
      2A) At this point, you can basically think of a namespace as a folder used to organize similar classes. For very big projects with hundreds of files, it is important to organize the files in this way.

  • @florianprock
    @florianprock 4 роки тому

    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 :)

  • @johnnguyen1655
    @johnnguyen1655 4 роки тому +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.

  • @gamnguyen3116
    @gamnguyen3116 5 років тому

    Thank you so much!

  • @anshulsaxena5991
    @anshulsaxena5991 5 років тому

    sir can you please make a series on mvc but only on php without framework

  • @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

  • @user-bi7nq4nj7q
    @user-bi7nq4nj7q 3 роки тому +1

    I couldnt get the namespace to work properly so I did the following, however, I havent figured out how to make it more dynamic than this (if /person changed I would need to re-write it to handle the change)
    spl_autoload_register('myAutoLoader');
    function myAutoLoader($className) {
    $path = "classes/";
    $extension = ".class.php";
    $subClass = "$path"."Person/" .$className . $extension;
    if (file_exists($subClass)){
    $fullPath = $subClass;
    //echo "true"; //Used to test if true
    } else {
    $fullPath = $path . $className . $extension;
    // echo "False"; //used to test if false
    }
    //to test output of new changes
    /* echo "";
    echo $subClass;
    echo "";
    echo $fullPath;
    */

  • @abiodunakinwande16
    @abiodunakinwande16 5 років тому

    thank you for this video.

  • @noiononfiniscosennoquestid6810
    @noiononfiniscosennoquestid6810 5 років тому +1

    Login system using PDO?

  • @Happystoreup
    @Happystoreup 5 років тому

    Thank you!