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 :)
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 ;)
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
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
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.
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.
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 !
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.
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!
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.
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.
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.
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.
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!
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)
For php 7.4 just add this line between $extension and $fullPath variable declarations : $className = str_replace("\\", DIRECTORY_SEPARATOR, $className);
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.
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!!!
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 ;)
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! :)
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.
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'; }
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.
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"
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 "" ?
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.
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
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.
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
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.
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; }
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?
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
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; }
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.
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
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)
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.
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!
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.
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 :)
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?
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.
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
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; */
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 :)
Somewhere in Germany you are helping a whole bunch of bachelor students... :)
upload full login system with pdo please...........
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 ;)
www.php.net/manual/en/function.autoload.php says that __autoload() "has been DEPRECATED as of PHP 7.2.0. "
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
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
THANK YOU! I've been looking all over as to what the problem might be. Should've looked in the comment section sooner.
thank you! you save me.
You save my day dude.
Thank you for saving my time
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.
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.
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 !
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.
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!
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.
I love how enthusiastically you teach!
You're the best PHP teacher. Thanks Dan
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.
This was a great PHP OOP 'good-housekeeping' lesson. Really helpful. Thank you.
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.
Same here, Thank you for the alternative solution.
your code is more simplier
keep going man i really enjoy each and every single episode you make
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!
spl_autoload_register('classLoader');
function classLoader($class){
$path = "classes/".$class.".class.php";
include_once $path;
}
this will also work.
Thanks man :)
spl_autoload_register(function($className){
include_once "classes/".$className.".class.php";});
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.
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!
Great! Man your tutorials about coding in PHP are one of the best on youtube!
Thank you so much for explaining it in such an interesting way that I'm watching it instead of Netflix on Sunday afternoon! :D
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.
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)
For php 7.4 just add this line between $extension and $fullPath variable declarations :
$className = str_replace("\\", DIRECTORY_SEPARATOR, $className);
I didn't learn namespaces yet, but your explanation about classes loading is really great.
Beautifully described by a graceful young man.
Great!
Man, thank you. Best instructing style that I've found out there.
Great content, and speech delivery is in a very high level, thank you man
I learned a lot from you Sir. Dan, 9 more episodes to go! Thank you so much for the lectures
You the best out there man... Thank you very much... My college teacher sucks
Thank you for again a nice video in order to learn me OOP!! Never te late to learn or dive into it later on.
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.
Elon Musk looks like you or you look like Elon Musk :-D
hehe same comment as i did in first video,
Best php channel. Good job Daniel, good job
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!!!
Thanks. Great teacher. Better than my college lecturar
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 ;)
Omg, Alex! Thank you very much! You saved the night and headache! :)
$fullPath = $path . str_replace('\\', '/', $className) . $extension; fixed my issue. Thank you very much!
Alex Heil Thank you so much.
Same from myside also.
Dude, fantastic explanation, you are a beast, congratulations
I am probably that early that the video isn't fully rendered to 720p quality :). Another nice tutorial.
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! :)
Ameeeeeen lol finally some good explanation about autoloading. Thanksss
Hello Daniel, can you please discuss about navigation and routing?
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.
Video quality?!
Anyway, best video so far :)
15:06 That was me. Jumped to 17th chapter. Got an error and watching this video. ;)
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';
}
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.
one of the best i have ever seen god bless you
I love all of your videos.
Great tutorials. When are you going to do Laravel?
Thanks for the videos bro !! Have a good day!
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"
Thanks bro :D
Brilliant as always
Very clear explanation, thanks a lot
Thank you man, you put it very simply.
Thank you brother, Great tutorial
Your tutorials are just awesome. :)
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?
Really love the new view, thanks Daniel
thank you man. you save my life;
Thank u so much for the work.. that helps us a lot
Thank you. Please more advanced php oop lessons.
That's it, THANKS!
Informative, usual....👍🏾
Perfect ,Thank You
Namespace sometime doesn't work if you leave any space before the php start tag "
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 "" ?
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.
Nice ending...for those who jumps at the middle and confuse all...😂😂😂
Thanks for all this wonderful videos.
You are awesome!!!!!
your videos are the best. can you take a video about Composer?? It would be great.
You are a osammm teacher , Thank you so much for your videos
Man ur a life saver.
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
Oh thank you, I was having the same problem... was about to throw my pc through the window
@@DawoopFilms I have the same problem too, threw my pc through the window, just take back
btw, i found that the Person in the path actually follows that word when i call the class person1 = new Person in index.php
Very good class my friend.
I love this lector, thank you!
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.
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
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.
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;
}
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?
I like your videos, i learn many of them.
that is amazing ! thanks a lot
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...
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
Is it safe to include all the classes? Does it slow down performance or anything?
Thank you Dani!
thank u dude u rescure my life :D
great 👍💗💗
please continue php
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;
}
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.
Thank you for adding this i was trying to figure it out...
I love your tutorial
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
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)
thsnks a lot Dani
so powerful video
hi your next videos contains register and login with pdo?
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.
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!
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.
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 :)
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?
yoooo thats what I was thinking about, its like magic
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.
Thank you so much!
sir can you please make a series on mvc but only on php without framework
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
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;
*/
thank you for this video.
Login system using PDO?
Thank you!