There was one thing in this lesson that I think might confuse people just starting out. It isn't normal to link directly to an include file from a form like this. The include file will not contain any of the HTML from the view (index.php in this case) and so when you submit your form the output will be missing things like your title, styles or other controls and content you have on the page. So instead what we do is link the form back to the view and add a conditional statement in index.php that reads if(isset($_POST['submit'])) include('includes/calc.inc.php'); This includes the calculator into the current view but only when the form has been submitted. Anyway, great video. Great series. There's always more to learn.
@@hearvie The point is, after user submit the form, all provided data goes to calc.inc.php using POST method. In this situation we are leaving calculator form forever :P because after calculation is done, the result is gonna be seen in calc.inc.php page after using echo. I understand that Dani did it just to show some practice example how to use classes, methods and properties but in real app, we should send the result back to form page and show it to the user. But now I think that @phyternl explained it much better than me so sorry if I confused you.
everyone talking about how good his lessons are... nobody talking about how handsome he's lookin' in this episode, the guy putting the extra effort for us, congrats m8
In my opinion, Calc should be renamed as Calculator. And the method calculator should be renamed as calculate. It is as per the "nice to have" convention that class should be named as Noun since it represents an object/thing and method should be named as a Verb since it represents an action that an object performs.
This is a super helpful series for those of us learning PHP. It would be great to see more in-depth real-world examples of how to deploy OOP PHP for web development, on tasks such as user authentication, password recovery, user account dashboards, shopping carts, etc. Thank you for everything that you're doing!
I tried making that, and I must say that what Daniel is doing is very VERY difficult. Making real-world example AND tech concepts is even more challanging, it is almost not worth the time. I have one tutorial like you describe it, and I am only at the very beginning after several hours and episodes
May i rant a little bit about the Tutorial? Hope people wont hate me. In PHP we have PSR standards, if you follow PSR-4 Autoloading you can easily implement external libraries within your code, so rather creating a file with .class i would follow the standard. You could use PSR-0 even it is deprecated. In your calc.inc.php you have a closing php Tag, according to the PSR-2, the closing tag tag MUST be omitted from files containing only PHP. You class i would rather call "Calculator" and the Method i would call "calculate" instead of switch case i would create private methods and use call_user_func_array to call the methods with a method_exists check before. Following defined standards is a good thing in my opinion, since all the Frameworks and Companies out there are following them, so if you know them early, it will be easier for you to work in a company/team.
Completely agree with your points about defined standards. Using call_user_func_array instead of switch is a matter of didactics, I personally wouldn't use that in this video, it's just a bridge too far for most people. I have to say that I find the use of an include file inside an action tag very peculiar, though.
Please make more videos, sir! I greatly enjoy your videos, very beginner friendly, very detailed and your chill attitude makes it looks like you enjoy it. I like the whole thing in general, I wrote a vbs bot to watch the shortest video in the list for 20 times, many thanks!
If you run this under Linux, make sure your class names (e.g., Calc) and file names (e.g., Calc.inc.php) use same cases. In this example, calc.inc.php won't work, as Unix-based systems are case-sensitive by default.
You could skip the need for the If statement altogether by using $path = __DIR__ . '/../classes/'; (double underscores around the DIR) It refers to a path in relation to the location of the class-autoload.inc.php file
Is it a good idea and practice to add "calculator" method inside __construct, and thus shorten the code inside calc.inc.php? Also, your explanations are simple and great!
Yo! Man, I love you so much. I have been trying to get a hang of OOP for quite a while now, but most youtube tutorial suck at explaining the concept well. You Just killed it bro.... I now understand the topic. Can you do a tutorial on PHP framework Yii
@mmtuts : hi, just a bit of confusion. you included class-autoload.inc.php in both index.php and calc.inc.php file. Do we really need the class files to be included in index? aren't we using the classes just in our calc.inc.php file?
you know that the most important thinks that i have learned in your courses is how to manage your code you know class folder includes folder so thank you very much
Anyway you can do it with Ajax so the result won't go to a new page but instead be displayed on the same page? That was we can use the calculator over and over again without having to go back to the index page?
Hi, Dani. Thank you a lot for your video. I hope you still answer questions on the topic. Towards the end of the video you said that the correct design pattern is to split class, execution and presentation code. I want to place the result so that the calculator can be used again immediately without the need of going back. Without AJAX, i must place the execution of the class in the presentation file, correct? Is it better to place the result in a $_SESSION global, redirect and then pull the result in the index page?
Well, good lesson. You could have written the Calc class better by using private attributes instead of public and editing switch by returning the result variable at the end of the function to avoid to repeat the code many times...
Why the whole if else check in the autoload function when you can use "require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/'. $className . $extension';"
I am new in terms of learning PHP. I learned Javascript before PHP, so I am sorry if this question makes no sense. Why do we need to post those data to another PHP page? Can it be done on the same page? The benefit to posting those data to another PHP is that our code looks cleaner? And if we posted those data on another PHP page, how can we use it on the index page? Do we have to use the session, return to the index page and access that particular value via session?
We send the data to another script file for a couple of reasons. 🙂 By doing so we make sure that the PHP code isn't run, unless the user actively triggers the need for it. Keeping PHP code in our HTML files (for example the index page), is only meant for code that is needed on that specific page. Like for example if we need PHP to write error messages on that page. And even then, I would personally just create a class named ErrorMessages, and have methods in there which can print various types of error messages, in case I need to use them multiple times. By splitting code into separate files, we also ensure that our HTML files don't become overly long or complex, which will both cause extra load times and cluttering in our files. This is one of the benefits of using classes, or even functions. And to answer your question, any data that needs to generally be accessible on your entire website, you store in the session for easy access. Let's say the users "username" for example, we don't want to fetch from the database EVERY time we need it, since it causes extra unnecessary load times.
I spent 2 hours troubleshooting the issue where it differs that you are using a case-insensitive OS. Can we recommend your next lessons be performed on a more industry standard OS? like Linux? Macos? None of the companies my friend are getting hired for are using windows os. Its frustrating when I think its your autoloader, but instead its a conflict caused by you capitalizing the class name. I apologize for the frustrated tone, your classes have been invaluable in learning OOP - Ive been learning how to debug, and getting in some good debug exp, which is definitely a required skill!
Do you have any documentation to prove that PHP classes and functions are different on different OS? 🙂 I know that some path naming might be different on different OS, but it seems very odd to me that the coding language itself changes. Would love to know if that’s the case. 🙂 But to answer the question, no I won’t be teaching the different variants if you are right about the OS, since I don’t have a Mac or Linux to test it out on. But honestly… in my 7 years I haven’t heard about the issue you are describing 😅
@@Dani_Krossing Thank you for your quick response! My debugging output was failing at two places initially: unable to find calc.inc.php and unable to find class “Calc” After placing echo all over the place in class-autoload.inc.php and directly including class-autoload.inc.php in calc.inc.php i was able to witness the autoloader’s mistake. I changed the class and its references in all files to “calc” and everything worked flawlessly. This worked for me, added right after the $className variable was assigned within the function myAutoLoader: function myAutoLoader ($className) { strtolower ($className); $url = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
No problem 🙂 Well, from glancing your code it seems your code isn’t like I taught in my “auto load tutorial”. In your code, you included a “strtolower()”, which is why your code can’t find the class in your autoload function, because you tell it to search for a lowercase class name. 🙂 So it isn’t a OS issue from what I can see, which seemed odd to me when you told me about it hehe. It is common practice to name your classes with a uppercase letter, so if I were you I would change my class name back and make sure your autoload looks like the one I showed in my tutorial. 🙂
@@Dani_Krossing i think you misunderstand; the added line is the final fix to the issue I was having. I did other things to show the case-sensitive issue, the strtolower() was the catch-all final fix to make the issue compatible cross-platform. Looking through the other comments, shows the issue isnt isolated to me. I eventually changed my class name(s) back to beginning with cap letter. But again, it wont work unless the strtolower() is in place. Glad to contribute however. When you update the videos, consider the diversity of our differing environments?
@@user-bi7nq4nj7q I'm a Linux user and run into the same problem. However I was trying to add your code to fix this issue bet... is it possible to get all file's code? Thanks
Whats the point of declaring the variable needs to be an integer, just to set it to be an integer yourself? Won't you get an error if you try to change text to an integer anyway? Either way you get an error, and have to make sure the input from user is an integer. So why take the extra step and declare strict mode?
Everything explained in this video has been a separate lesson leading up to this video. As well as “autoload” 🙂 If you didn’t skip those videos, then I can’t explain it any better.
@@Dani_Krossing i did watch your autoload video in this playlist, the thing is I am confused on why are you changing it and pls do explain the change code bit more.
retrying this activity again, because I can't find where to fix the error T-T autoload is taking its class name from the submit button. for ex. add.class.php. Hope I figure it out :< or maybe get some help in the comments
Hi Mr Daniel I've watched your videos and they're superb thanks so much for everything but I have a problem with one. The comments video...when I click submit, the comments don't go into the database. Please help😭🙏
Very nice tutorial up to now. I like your style and pacing a lot. It's just... you do use some peculiar or old-fashioned conventions, it's best to stick to PSR in my opinion. However, there's one thing that left me a bit flabberghasted and that's the include file which you put in the form action. That's as weird as prime beef in a sausage. I understand that you want to promote separation of concerns, but why not make a copy of index.php, ditch the form and put everything from calc.inc.php in there? Or just include calc.inc.php if you really want to use an include? Anyway, that't up till now my only peeve, the rest of the course gets an 11 out of 10.
bah I'm a bit stuck, I've checked all my; and I'm sure they are all there. everything seems to run fine, but I get my default echo from my switch, but ive checked that over and over and over and its the same. !! Does anyone have this code on git hub, so that i can copy and paste bit by bit to try and find my error.
It's not really explained why the calculation needs to be done in a separate document. If you check out the page source, you'll see that no PHP code is present. This means that the entirety of PHP logic is resolved on the server. So, unless you use JavaScript to make the calculation inside the browser (and handle the DOM changes) you need to send a request back to the server so that PHP can spring into action. Essentially, calc.inc.php is another HTML page that the server computes and sends back to the client upon submitting the form. The calculation itself could have been resolved with a calculator function from inside calc.inc.php but having it as a class method serves two purposes. 1. It detaches the logic to a separate file, making it reusable; 2. it makes its context easier to read and understand.
There are a couple of reasons for why we send the data to a separate file. 🙂 I can see how in this particular project you might not see the benefits, since it is just a VERY basic example. But later on once you start getting a bit more into security, and need to learn how to properly handle user submitted data, then you will be glad that you learned how to do it "the correct way". But here are a few reasons for why you shouldn't create all PHP on the same page: 1. At some point you will start to have A LOT of PHP inside your website, and having it ALL inside your main pages is extremely cluttered. So separating the tasks into different files is considered best practice. You should ONLY keep PHP on your web pages, that are absolutely necessary. 2. When it comes to user submissions through an input, we want to have the data sanitized and most likely run a handful of error handlers, to check that the data was properly submitted. Which is a lot easier to do in a separate script. 3. When you submit data using a post or get method, we want to make sure that we DON'T run the following PHP script, unless it was submitted correctly, which is also easier using separate pages. Just to name a few. 🙂
I'm watching your series to learn OOP in PHP (I've been using OOP in other languages for ages and I've been using PHP for ages, just never OOP PHP) and the videos are great for this purpose. But if I try to imagine a person who is also learning OOP from these videos, I think he could get really confused now. Because this must be the worst example of a practical use of a class I've ever seen :-) Why would you store the two numbers and the operator in class properties using the constructor, just to be able to call a method to do some calculation on them and then never use them again? I would probably ask - oh wait, couldn't you just make a function compute(int $a, int $b, string $operator)? Please don't take me wrong, I think you are a great teacher and your videos taught me a lot in a short time. But I think that even a negative feedback can be usefull ;-)
Excellent course.....but please make a fullstack complete project with php oops like social media blogpost like that till uploading to the server...thank you
Hi @mmtuts Why you use in class-autoload.inc.php if(strpos($url, 'includes') !== false){ not if(strpos($url, 'includes') == true){ // Maybe it's better to understand it how it works . And when we talking about OOP maybe it's better way to create function for check $url ? Like this: function currentUrl() { $host = $_SERVER['HTTP_HOST']; $script = $_SERVER['REQUEST_URI']; return $host . $script ; } And when we want add something we just change the function. I would know what you think about it
if(strpos($url, 'includes') == true) this statement is wrong, it works because php can convert any number to true. the strpos function returns either false or a number, so it is correct to ask if the result is not false.
There was one thing in this lesson that I think might confuse people just starting out. It isn't normal to link directly to an include file from a form like this. The include file will not contain any of the HTML from the view (index.php in this case) and so when you submit your form the output will be missing things like your title, styles or other controls and content you have on the page. So instead what we do is link the form back to the view and add a conditional statement in index.php that reads if(isset($_POST['submit'])) include('includes/calc.inc.php'); This includes the calculator into the current view but only when the form has been submitted. Anyway, great video. Great series. There's always more to learn.
Thank you!
I feel like i get you but I don't. I'm confused lol. Anyway to contact you?
@@hearvie The point is, after user submit the form, all provided data goes to calc.inc.php using POST method. In this situation we are leaving calculator form forever :P because after calculation is done, the result is gonna be seen in calc.inc.php page after using echo. I understand that Dani did it just to show some practice example how to use classes, methods and properties but in real app, we should send the result back to form page and show it to the user. But now I think that @phyternl explained it much better than me so sorry if I confused you.
Since 2015 and you are still making PHP video. That is such dedication. Love to you Daniel
everyone talking about how good his lessons are... nobody talking about how handsome he's lookin' in this episode, the guy putting the extra effort for us, congrats m8
Mate you're an absolute legend. I love your tutorials. You're so thorough and easy to follow. Thank you and please keep them coming.
Put all the pieces together and I was able to create a signup form using the MVC model. Honestly so thankful for your tutorials. Thank you!
In my opinion, Calc should be renamed as Calculator. And the method calculator should be renamed as calculate. It is as per the "nice to have" convention that class should be named as Noun since it represents an object/thing and method should be named as a Verb since it represents an action that an object performs.
As I go through your course, I express my gratitude, like and comment ' thank you' on each video.
I am watching this video from Japan! and I am totally big fan of this guy right here!!! thank you for all of your lessons that helps me a lots!!
This is a super helpful series for those of us learning PHP. It would be great to see more in-depth real-world examples of how to deploy OOP PHP for web development, on tasks such as user authentication, password recovery, user account dashboards, shopping carts, etc. Thank you for everything that you're doing!
I tried making that, and I must say that what Daniel is doing is very VERY difficult. Making real-world example AND tech concepts is even more challanging, it is almost not worth the time. I have one tutorial like you describe it, and I am only at the very beginning after several hours and episodes
What an awesome video series! You make it much easier to understand not just what we're doing but why we're doing it! Great Job!!
You're the best teacher ever, thank you so much I going to watch the entire course because I want to be an expert php programmer also.
Learned oops so many times but applied it the first time in some useful way. Thanks, Dani
May i rant a little bit about the Tutorial? Hope people wont hate me.
In PHP we have PSR standards, if you follow PSR-4 Autoloading you can easily implement external libraries within your code, so rather creating a file with .class i would follow the standard. You could use PSR-0 even it is deprecated.
In your calc.inc.php you have a closing php Tag, according to the PSR-2, the closing tag tag MUST be omitted from files containing only PHP.
You class i would rather call "Calculator" and the Method i would call "calculate" instead of switch case i would create private methods and use call_user_func_array to call the methods with a method_exists check before.
Following defined standards is a good thing in my opinion, since all the Frameworks and Companies out there are following them, so if you know them early, it will be easier for you to work in a company/team.
@@RameenFallschirmjager no books just phptherightway.com and do project and ask on stack overflow. Don't just read. Solve your problems
@@RameenFallschirmjager actually the projects finds YOU;) start with your personal homepage/blog. solve YOUR problems
@@RameenFallschirmjager in 2000 we used to have a Guestbook on our webpage, create a guestbook with administration backend where you can edit entries
Completely agree with your points about defined standards. Using call_user_func_array instead of switch is a matter of didactics, I personally wouldn't use that in this video, it's just a bridge too far for most people. I have to say that I find the use of an include file inside an action tag very peculiar, though.
You really saved my lab assignment!!! I have never found any other videos that have enough example step by step like yours. Thank you seriously! :-)
Hey Dani, I think your tutorials are great. I‘ve been following them for many years now.
Nice, thanks - Fix an error in class.autoload.inc.php - in the last line:
require_once strtolower($path . $className . $extention);
Please make more videos, sir! I greatly enjoy your videos, very beginner friendly, very detailed and your chill attitude makes it looks like you enjoy it. I like the whole thing in general, I wrote a vbs bot to watch the shortest video in the list for 20 times, many thanks!
I've heard your Nintendo joke for the third time now and it really just gets more and more funny each time
If you run this under Linux, make sure your class names (e.g., Calc) and file names (e.g., Calc.inc.php) use same cases. In this example, calc.inc.php won't work, as Unix-based systems are case-sensitive by default.
Great video, Daniel! You are the best PHP-instructor on youtube:D Also, I liked the "Switch"-Joke haha
You could skip the need for the If statement altogether by using
$path = __DIR__ . '/../classes/';
(double underscores around the DIR)
It refers to a path in relation to the location of the class-autoload.inc.php file
subtle flex on the leather jacket? hahaha good video!
Great tut, Daniel! :)
That leather jacket suits you very well! 👌
very simple and very clean thank you
Just one word, awesome.
You deserve more views!!! Your lessons are great. Keep it up
You just save my life 🙂, I feel very emotional right now 😭, do you have any tutorial on REST API, please I need that
omg, i have learned a lot of oops here, thanks Dannii
Great Tutorial !!
thank you for your video tutorials and you rock that leather jacket coz u look super cool in it! keep up the good work!
excelent teacher good 100%
Is it a good idea and practice to add "calculator" method inside __construct, and thus shorten the code inside calc.inc.php? Also, your explanations are simple and great!
Love the look of the new office!😂
Yo! Man, I love you so much. I have been trying to get a hang of OOP for quite a while now, but most youtube tutorial suck at explaining the concept well. You Just killed it bro.... I now understand the topic.
Can you do a tutorial on PHP framework Yii
Daniel, you my angel of knowledge, thanks alot:)
Great video series, really engaging and easy to follow, thank you!
You don't really need that else statement on $path. Just declare it values before the if :) Either way, great vid ^^
@mmtuts : hi, just a bit of confusion. you included class-autoload.inc.php in both index.php and calc.inc.php file. Do we really need the class files to be included in index? aren't we using the classes just in our calc.inc.php file?
exactly my question..
you know that the most important thinks that i have learned in your courses is how to manage your code you know class folder includes folder so thank you very much
These videos are very good. I got it now, or getting it.
Anyway you can do it with Ajax so the result won't go to a new page but instead be displayed on the same page? That was we can use the calculator over and over again without having to go back to the index page?
Thank you for the lessons.
calc is calculator btw if youre new here.. he's just using slang
Thanks, really nice simple projekt
Great explained for beginners!
Hi, Dani. Thank you a lot for your video. I hope you still answer questions on the topic.
Towards the end of the video you said that the correct design pattern is to split class, execution and presentation code.
I want to place the result so that the calculator can be used again immediately without the need of going back.
Without AJAX, i must place the execution of the class in the presentation file, correct?
Is it better to place the result in a $_SESSION global, redirect and then pull the result in the index page?
thanks for your videos Daniel
Should not the constructor method be in the try catch?
If a type error occurs, there will be already an error in the constructor
Nice jacket. You should put some heavy metal music in the background this time!
Really helpful...
Well, good lesson. You could have written the Calc class better by using private attributes instead of public and editing switch by returning the result variable at the end of the function to avoid to repeat the code many times...
I completely agree, that would improve this video. 🙂 I always cringe when watching my past coding convention. 😅 Luckily I don't have them today.
I just love this dude :)
New jacket + new office! !!!
Ooh, your leather jacket is cool!
the if condition in the autloader could be simpler:
$path = "classes/";
if (strpos($url, 'includes')) {
$path = "../classes/";
}
9:09 Oper.
.
.
.
.
.
.
.
.
.
.
>rator
by the way, love your tuts, man
Why the whole if else check in the autoload function when you can use "require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/'. $className . $extension';"
I am new in terms of learning PHP. I learned Javascript before PHP, so I am sorry if this question makes no sense. Why do we need to post those data to another PHP page? Can it be done on the same page? The benefit to posting those data to another PHP is that our code looks cleaner? And if we posted those data on another PHP page, how can we use it on the index page? Do we have to use the session, return to the index page and access that particular value via session?
We send the data to another script file for a couple of reasons. 🙂 By doing so we make sure that the PHP code isn't run, unless the user actively triggers the need for it.
Keeping PHP code in our HTML files (for example the index page), is only meant for code that is needed on that specific page. Like for example if we need PHP to write error messages on that page. And even then, I would personally just create a class named ErrorMessages, and have methods in there which can print various types of error messages, in case I need to use them multiple times.
By splitting code into separate files, we also ensure that our HTML files don't become overly long or complex, which will both cause extra load times and cluttering in our files. This is one of the benefits of using classes, or even functions.
And to answer your question, any data that needs to generally be accessible on your entire website, you store in the session for easy access. Let's say the users "username" for example, we don't want to fetch from the database EVERY time we need it, since it causes extra unnecessary load times.
@@Dani_Krossing Thank you! I understood now!
subscribed at the cool leather jacket moment
Thank you
I spent 2 hours troubleshooting the issue where it differs that you are using a case-insensitive OS. Can we recommend your next lessons be performed on a more industry standard OS? like Linux? Macos? None of the companies my friend are getting hired for are using windows os. Its frustrating when I think its your autoloader, but instead its a conflict caused by you capitalizing the class name. I apologize for the frustrated tone, your classes have been invaluable in learning OOP - Ive been learning how to debug, and getting in some good debug exp, which is definitely a required skill!
Do you have any documentation to prove that PHP classes and functions are different on different OS? 🙂
I know that some path naming might be different on different OS, but it seems very odd to me that the coding language itself changes.
Would love to know if that’s the case. 🙂 But to answer the question, no I won’t be teaching the different variants if you are right about the OS, since I don’t have a Mac or Linux to test it out on. But honestly… in my 7 years I haven’t heard about the issue you are describing 😅
@@Dani_Krossing Thank you for your quick response! My debugging output was failing at two places initially: unable to find calc.inc.php and unable to find class “Calc”
After placing echo all over the place in class-autoload.inc.php and directly including class-autoload.inc.php in calc.inc.php i was able to witness the autoloader’s mistake. I changed the class and its references in all files to “calc” and everything worked flawlessly. This worked for me, added right after the $className variable was assigned within the function myAutoLoader:
function myAutoLoader ($className) {
strtolower ($className);
$url = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
No problem 🙂 Well, from glancing your code it seems your code isn’t like I taught in my “auto load tutorial”.
In your code, you included a “strtolower()”, which is why your code can’t find the class in your autoload function, because you tell it to search for a lowercase class name. 🙂
So it isn’t a OS issue from what I can see, which seemed odd to me when you told me about it hehe.
It is common practice to name your classes with a uppercase letter, so if I were you I would change my class name back and make sure your autoload looks like the one I showed in my tutorial. 🙂
@@Dani_Krossing i think you misunderstand; the added line is the final fix to the issue I was having. I did other things to show the case-sensitive issue, the strtolower() was the catch-all final fix to make the issue compatible cross-platform. Looking through the other comments, shows the issue isnt isolated to me. I eventually changed my class name(s) back to beginning with cap letter. But again, it wont work unless the strtolower() is in place. Glad to contribute however. When you update the videos, consider the diversity of our differing environments?
@@user-bi7nq4nj7q I'm a Linux user and run into the same problem. However I was trying to add your code to fix this issue bet... is it possible to get all file's code? Thanks
The switch joke had me dying XD
well explained. I love it.
Pls make more exercise a practical one that we can use them inside our website ❤ love ur tutorials
just adapt and use the code you learned
I got an error (unsupported declare_types) and I am using php version 5.6.38....
Kindly any one tell me what i will do?
0:20 "This is my new office in case you didn't know" (proceeds to remove the background)
i always use double quotes for string, isn't that bad practice?
honestly, i really laughed with your Nintendo switch joke :))
Smooth $operator!!
Smooooooth $operaateaaar!
@@Dani_Krossing xD
Whats the point of declaring the variable needs to be an integer, just to set it to be an integer yourself?
Won't you get an error if you try to change text to an integer anyway? Either way you get an error, and have to make sure the input from user is an integer.
So why take the extra step and declare strict mode?
he did it on purpose so you could point it out and then share it with us
he's a master teacher
That switch joke was terrible, but in the good way. I also laughed on your self reaction :D:D
Nice video elon musk
hahah
It is more a rare mixture between Elon and Mr.Beast.
Thanks so much for this video. its really Helpful. Do you mind creating a series with Laravel or send me the link if you already have one?
Get rid of that Microphone :)
Anyway, nice to see you in Action again and wish you success!
Nah, the sound is amazing, keep the mic.
@@dejangegic it's just a Taste. That was my opinion! You can write yours and not answer to mine...
just to let you know I didn't understand a thing maybe you should explain more on auto load and why you do these changes!
Everything explained in this video has been a separate lesson leading up to this video. As well as “autoload” 🙂 If you didn’t skip those videos, then I can’t explain it any better.
@@Dani_Krossing i did watch your autoload video in this playlist, the thing is I am confused on why are you changing it and pls do explain the change code bit more.
To anyone who might know the answer. Is it possible to display the results in the index.php page? Other than using the header() function.
retrying this activity again, because I can't find where to fix the error T-T autoload is taking its class name from the submit button. for ex. add.class.php. Hope I figure it out :< or maybe get some help in the comments
there is no use of // include "includes/ClassAutoLoader.php"; in top of index.php please correct me if i am wrong
Yea the reason for the separate file is because of the "Form action"
neat automaticly casted into float when do division
Hi Mr Daniel I've watched your videos and they're superb thanks so much for everything but I have a problem with one. The comments video...when I click submit, the comments don't go into the database. Please help😭🙏
Thanks! Can you give us some PHP_HOMEWORK?
Very nice tutorial up to now. I like your style and pacing a lot. It's just... you do use some peculiar or old-fashioned conventions, it's best to stick to PSR in my opinion. However, there's one thing that left me a bit flabberghasted and that's the include file which you put in the form action. That's as weird as prime beef in a sausage. I understand that you want to promote separation of concerns, but why not make a copy of index.php, ditch the form and put everything from calc.inc.php in there? Or just include calc.inc.php if you really want to use an include? Anyway, that't up till now my only peeve, the rest of the course gets an 11 out of 10.
bah I'm a bit stuck, I've checked all my; and I'm sure they are all there. everything seems to run fine, but I get my default echo from my switch, but ive checked that over and over and over and its the same. !!
Does anyone have this code on git hub, so that i can copy and paste bit by bit to try and find my error.
It's not really explained why the calculation needs to be done in a separate document. If you check out the page source, you'll see that no PHP code is present. This means that the entirety of PHP logic is resolved on the server. So, unless you use JavaScript to make the calculation inside the browser (and handle the DOM changes) you need to send a request back to the server so that PHP can spring into action.
Essentially, calc.inc.php is another HTML page that the server computes and sends back to the client upon submitting the form.
The calculation itself could have been resolved with a calculator function from inside calc.inc.php but having it as a class method serves two purposes. 1. It detaches the logic to a separate file, making it reusable; 2. it makes its context easier to read and understand.
There are a couple of reasons for why we send the data to a separate file. 🙂 I can see how in this particular project you might not see the benefits, since it is just a VERY basic example. But later on once you start getting a bit more into security, and need to learn how to properly handle user submitted data, then you will be glad that you learned how to do it "the correct way".
But here are a few reasons for why you shouldn't create all PHP on the same page:
1.
At some point you will start to have A LOT of PHP inside your website, and having it ALL inside your main pages is extremely cluttered. So separating the tasks into different files is considered best practice. You should ONLY keep PHP on your web pages, that are absolutely necessary.
2.
When it comes to user submissions through an input, we want to have the data sanitized and most likely run a handful of error handlers, to check that the data was properly submitted. Which is a lot easier to do in a separate script.
3.
When you submit data using a post or get method, we want to make sure that we DON'T run the following PHP script, unless it was submitted correctly, which is also easier using separate pages.
Just to name a few. 🙂
@@Dani_Krossing Good points. I did see benefits though, as I described. :)
I'm watching your series to learn OOP in PHP (I've been using OOP in other languages for ages and I've been using PHP for ages, just never OOP PHP) and the videos are great for this purpose. But if I try to imagine a person who is also learning OOP from these videos, I think he could get really confused now. Because this must be the worst example of a practical use of a class I've ever seen :-) Why would you store the two numbers and the operator in class properties using the constructor, just to be able to call a method to do some calculation on them and then never use them again? I would probably ask - oh wait, couldn't you just make a function compute(int $a, int $b, string $operator)? Please don't take me wrong, I think you are a great teacher and your videos taught me a lot in a short time. But I think that even a negative feedback can be usefull ;-)
Excellent course.....but please make a fullstack complete project with php oops like social media blogpost like that till uploading to the server...thank you
you are cool.
there is no need for the include and strict mode decleration in the Html code
Hi @mmtuts
Why you use in class-autoload.inc.php
if(strpos($url, 'includes') !== false){
not
if(strpos($url, 'includes') == true){ // Maybe it's better to understand it how it works .
And when we talking about OOP maybe it's better way to create function for check $url ?
Like this:
function currentUrl() {
$host = $_SERVER['HTTP_HOST'];
$script = $_SERVER['REQUEST_URI'];
return $host . $script ;
}
And when we want add something we just change the function.
I would know what you think about it
if(strpos($url, 'includes') == true) this statement is wrong, it works because php can convert any number to true. the strpos function returns either false or a number, so it is correct to ask if the result is not false.
@@VitalijMik Thank you, you are right :)
Why wouldn't you just use procedural "if" statements to handle what to do with the posted numbers? This seems like Ironically more work.
Why not use PSR-2 and PSR-4?
You look kinda like Elon Musk. Good course BTW.
Now I can see 😁
19:45
I see why this is used... I just love progressive PHP instead of OOP... Why? IDK...
I didn't get a point.. you haven't linked the button submit within the php so how it worked out !?
I linked the form, not the submit button.
This is what is called VMC Model ??
Need more example! Thank you!
Examples of php calculator or what ?
Hope it doesn't *SQUEAK* get captured by the microphone.
LOL.