Stop Doing This in PHP... | Avoid Nesting If Statements | Better Coding Habits in PHP

preview_player
Показать описание
In this video I will show you how to write clean code in PHP, when it comes to conditions. You will learn how to avoid nesting if conditions, to get better coding habits in PHP. Better coding practices is something we should all continue to get better at, so hopefully this tip will give some of you something useful.

Better Coding Habits in PHP, php nesting, php nesting level too deep, avoid nesting if statements, clean code, if else statement, guard clauses, else statement, clean code in php, how to write clean code in php, php tips, php tips and tricks, php tips and tricks advanced, php pro tips, better coding practices, clean code horrible performance, clean code php, php conditions best practices, php best practices coding standards, php less messy conditions

➤ GET ACCESS TO MY LESSON MATERIAL HERE!

First of all, thank you for all the support you have given me!

I am really glad to have such an awesome community on my channel. It motivates me to continue creating and uploading content! So thank you!

I am now using Patreon and YouTube Memberships to share improved and updated lesson material, and for a small fee you can access all the material either from my memberships or Patreon, depending on your preference. I have worked hard, and done my best to help you understand what I teach.

I hope you will find it helpful :)

Рекомендации по теме
Комментарии
Автор

Dani I guess you forgot to delete the exclamation mark(s) on line 12

TuncayKaptan
Автор

The best php teacher thanks alot mr dani complete please and upload more videos

phpcoderforever
Автор

Obviously there are sometimes cases where a small amount of nested conditionals are probably going to be perfectly fine, but for the most part, this method works really well.

scott-richardson
Автор

Back to PHP. You are a great teacher sir! Well done sir

samnako
Автор

Great video, as usual! It could have been a great opp to introduce shorthands tho - unless you already made a video about it already. Anyway, thanks for what you do! We need to keep PHP alive :)

cryptoknight
Автор

As usual very interesting, THANK you!

Lyrik-Klinge
Автор

Your videos are always so informative and well-presented. Thank you for sharing your knowledge with us!🚀😎

MyCodingDiary
Автор

This advice is so helpful my friend! Thanks for sharing this. I don’t get why ppl are complaining about your „errors“, as this video is about explaining a concept, not a specific piece of code. 😅

UrduHedef
Автор

Keep your code lean and mean. Negation is key here 🙂 I always say to friends & family, don't be so negative, but if you're actually in coding mode, you want to be very negative at times.

PicSta
Автор

I know it's just a quick demonstration of the concept, but I would think that you would want to test if the SERVER variables were empty, as trying to assign them when they are not there would get errors. I know, because I have had that issue with my own code previously.

javabeanz
Автор

I wouldn't recommend using empty as it takes falsly values as empty (0, 0.0, null, false, etc..) but I get what you're trying to show of course.

Hefss
Автор

You are amazing teacher. Please make a video of how to build php for backend and javascript for frontend together as a fullstack, so we could know how frontend and backend integrates .... There are very few videos out there, that have both js and php included project.

seeker
Автор

Thnx for this amazing video, Can you explain us that how can we do an image and a video upload, insert, delete, select from database

mortwain
Автор

3;48 From what I have read from multiple Website, Die and Exit are basically the same

Alexifeu
Автор

Dani, can you do us a file / image upload, retrieve, delete and update system in php on a live server? I think this almost doesn't exist on youtube. Consider it please. You are a great teacher again.

samnako
Автор

Most nesting, in C/C++, is actually from maintance mode, where the desire, is to change the code the least, but have the new condition. After a few years, you'd added 20+ more conditions (lol). There is one piece of code I remember, that had no validation. The validation occured before it was called. But then things changed. After three years, I'm looking at 3 years of trivial changes, thinking, I would not have done it this way from the beginning. I added a java validation external program, and left the damage in place. But, it got weird. One week at a time. 600+ companies exchanging files, and someone can argue the definition of zero.

normbograham
Автор

Hi Dani,

once again a great video - I know I'm late but I'm reviewing what you did the last years and it is a pleasure!!!

I am one of those nesters indeed and I wonder what to do when "if-elsing", what I commonly do when my nesting "happens". My workaround commonly was to extract such nestings into decision-functions. Often this can be useful as similar decisions can be made at several spots inside a project.
Is there a way to jump right to the else condition? From my old C-programming times I remember people telling me that jumping points are no good way to programm. I guess thats only if you jump forth and back, do you agree?

Best
Christian

fulgorth
Автор

3:48 No, exit and die are exactly the same like aliases. In other languages they differ, but not in php.

darvinde
Автор

I have a legacy project built using a "true Indian coding guidelines": with a nesting level up to 6, and files length up to 5000-8000 lines (20-40K).
I hoped, you'll show some ingenious "hack" to solve the nesting ifs' problem, I can utilize, but unfortunately, I know "the catch" which is on your video for quite a time :)/

towndwarf
Автор

Would it make sense to create external validation classes for certain conditions, that could eventually move to a parent class to make them accessible elsewhere?

KwonDo-Hyung