Autoloading Classes in PHP: PSR-4 and Composer

  Рет қаралды 1,596

Dave Hollingworth

Dave Hollingworth

Күн бұрын

Пікірлер: 34
@dave-hollingworth
@dave-hollingworth Ай бұрын
Thank you for watching! Please consider supporting my channel: ☕ko-fi.com/davehollingworth
@ahmad-murery
@ahmad-murery Ай бұрын
Even though I already know how PSR4 and spl_autoload_register work, I still found this video is very well organized and easy to follow. Thanks Dave!
@ianw9349
@ianw9349 Ай бұрын
Many thanks, Dave. Your videos are always so clear. A great pleasure to learn from you.
@MemoryMire
@MemoryMire Ай бұрын
You can be a high paid influencer with this chill voice and clear accent. I wish to see a detailed Laravel course from your voice and significant teaching skills.
@pythonantole9892
@pythonantole9892 Ай бұрын
This was so helpful. I have learned alot and now understand the namespace declarations and use statements in frameworks like CI4 (learning CodeIgniter 4 from your course.)
@joel-rg8xm
@joel-rg8xm Ай бұрын
Thanks for such a clear explanation
@sam-j4zy
@sam-j4zy Ай бұрын
This is great, thanks alot for sharing sir.
@ploob1
@ploob1 15 күн бұрын
The Hivemind Has Found It's Next Victim
@NedumEze
@NedumEze Ай бұрын
Dave, thanks so much. The best handling of this topic ever. Never seen anything near as good. I need your help. A question please. Too often I am forced reinstall Composer! Is that your experience? I install it globally. And in days, when I need it in another Project, I get the crazy message "command not found"! What am I doing wrong. I run on Windows and Wampserver
@dave-hollingworth
@dave-hollingworth Ай бұрын
Thank you for your kind words! I've never experienced that I'm afraid. It could be a Windows thing - I have experienced Windows uninstalling programs before. I did a quick search and can't find any references to this problem. Maybe install it as administrator?
@NedumEze
@NedumEze Ай бұрын
@dave-hollingworth I did install it the last time as Administrator. Thanks for all your selfless help
@dave-hollingworth
@dave-hollingworth Ай бұрын
@@NedumEze Try installing it locally to each project, see if that makes a difference (i.e. composer.phar is inside your project folder)
@NedumEze
@NedumEze Ай бұрын
@dave-hollingworth Oh! Okay. I will try it out. Maybe the answer. Global installation has been a pain. Does NOT PERSIST for me. Thank you very much, Dave
@dmxd
@dmxd Ай бұрын
Dave, what code editor and the theme/color scheme you use in this video?
@dave-hollingworth
@dave-hollingworth Ай бұрын
Visual Studio Code, and this theme: www.vscolors.com/themes/bf8aa94a-4051-42fe-9bd1-2becad466fe7-41e84e99
@3minutes.official
@3minutes.official Ай бұрын
Thank youuuuu 😍😍😍😍 am understand OOP and create class sample and route path we give more sample course OOP 🎉🎉🎉❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤ keep up 👍🏻👍🏻👍🏻👍🏻👍🏻👍🏻👍🏻👍🏻
@abdelhamidnehlil7277
@abdelhamidnehlil7277 27 күн бұрын
merci
@MobiusCoin
@MobiusCoin Ай бұрын
What makes the spl_autoload_register() special? Why can't just write what is equivalent to its callback function and just use that?
@dave-hollingworth
@dave-hollingworth Ай бұрын
I'm not sure what you mean, but spl_autoload_register registers a function that is called automatically when the PHP interpreter doesn't find a class that's being used. It gives the code a chance to load it before a "class not found" error occurs.
@MobiusCoin
@MobiusCoin Ай бұрын
@@dave-hollingworth I guess what I mean is why can't I do this: function load_scripts($class) { require $class . '.php'; } load_scripts('app'); at the beginning of the file?
@dave-hollingworth
@dave-hollingworth Ай бұрын
@@MobiusCoin You could, but that function wouldn't be called automatically if a class wasn't found, you'd still have to explicitly load them. With spl_autoload_register, when PHP comes across a class that hasn't been defined yet, e.g. $user = new User; if there is an autoload function this will be called. Inside the autoload function you can require the class, then the PHP interpreter goes back to where it was when it came across the class.
@MobiusCoin
@MobiusCoin Ай бұрын
@@dave-hollingworth ahh got it, thanks
@jediampm
@jediampm Ай бұрын
Hi Mr.Dave, thanks for the video. Also is missing the info that composer also is capable of load files, which can have functions or constants. Also to be a complete / detail about autoload with composer, mention about classmap and psr-0. Thanks anyway.
@rustamergashev7278
@rustamergashev7278 Ай бұрын
👍
@rafanarafana
@rafanarafana Ай бұрын
Hi, Dave. Can you add a polish soundtrack? Many people from Poland are watching you. Thank you for your tutorials.
@dave-hollingworth
@dave-hollingworth Ай бұрын
The alternative languages are added automatically by KZbin. I'll see if there's an option for a Polish one.
@tanzimibthesam5861
@tanzimibthesam5861 25 күн бұрын
I dont know why you didnt include autoload in your MVC course
@dave-hollingworth
@dave-hollingworth 24 күн бұрын
I do have a plan to include it, when I eventually get around to it!
@3minutes.official
@3minutes.official Ай бұрын
😅 my English very sample am learning languages 🤦🏻🤣 thank you 🎉🎉❤❤❤
@Wizatek
@Wizatek Ай бұрын
I am not a fan of namespaces in PHP, i never use them
@Mr.Jacks-s5q
@Mr.Jacks-s5q Ай бұрын
Please, if you make the audio track in your video Bengali, it would be beneficial for us Bangladeshis or those who follow you from my Bangladesh country. Please please bangla the audio track. ☺☺
@dave-hollingworth
@dave-hollingworth Ай бұрын
I'd love to help, and I'll look into it, but I doubt I'll have time right now - if you provide the audio track in Bengali though I'd be happy to upload it to the video
Routes, Routers and Routing in PHP
17:27
Dave Hollingworth
Рет қаралды 1,3 М.
Почему Катар богатый? #shorts
0:45
Послезавтра
Рет қаралды 2 МЛН
The Lost World: Living Room Edition
0:46
Daniel LaBelle
Рет қаралды 27 МЛН
How I Scaled My Online Coaching Biz To $30M
31:32
Charlie Morgan Business
Рет қаралды 1,1 М.
Use Composer to Easily Manage PHP Packages
15:40
Dave Hollingworth
Рет қаралды 11 М.
Learn Symfony in 1 Hour
1:11:01
Dave Hollingworth
Рет қаралды 9 М.
I Built the Same App in ALL Versions of PHP (1995-2025)
12:28
Coding with Lewis
Рет қаралды 68 М.
Parse JSON in PHP | How to validate and process nested JSON data
12:20
Dave Hollingworth
Рет қаралды 3,6 М.
Best of CES 2025
14:50
The Verge
Рет қаралды 626 М.
ARRAYLIST VS LINKEDLIST
21:20
Core Dumped
Рет қаралды 89 М.
When to use Traits, Interfaces, and Abstract Classes in PHP
15:08
Andrew Schmelyun
Рет қаралды 25 М.