PHP Abstract Classes & Methods - Full PHP 8 Tutorial
Вставка
- Опубліковано 18 вер 2024
- In the previous lesson we covered inheritance, in this video, you'll learn about abstract classes & abstract methods. Abstract classes use inheritance so if you have not watched the last lesson about inheritance please make sure to watch that first since the same rules apply to abstract classes.
SOME OF THE WAYS YOU CAN SUPPORT THE CHANNEL
👍 Smash the like button
🤝 Subscribe to the channel & turn the notifications on
💬 Post comments, any feedback is greatly appreciated
⭐ Become a Patreon: / programwithgio
THANK YOU!
LESSON 2.10
Course Outline - github.com/gge...
Course Playlist - • Learn PHP The Right Wa...
If I'm not in any rush, I don't skip ads to support your channel. I'm not gonna surprise if this channel will grow more and more in the near future. You're now one of my favorite instructors here in UA-cam. :)
Thank you so much, happy to hear that & I appreciate the support
Oh my god, completely forgot about ads, from now i'll turn off the adblock for this channel
I watched many php related courses but without any doubt i want to say that your course is best php course on entire youtube
thank you for providing us such a valuable content
now i understand much more in oop because of you
and i want that you make a course on laravel also
i would be very grateful if you did
Thank you 🙏. I plan on making Laravel course, don't have the date yet though
If I pass the job interview, I'll buy you something. Thank you so much so much for these videos.
That's very kind of you but you passing the interview will be more than enough for me. Best of luck, I'm sure you'll ace it 🙌
Best php class and oop tutorial
Clear explanation. I am learning couple of things from your every videos. Thanks much
You're welcome, happy to hear that my videos are helpful 🙌
great tutorial, pls upload more complex OOP PHP features
Thank you. We're moving to more complex & advanced PHP with each new lesson 👍
Great lesson. I'm really counting on more exposure. To really know when to implement abstract classes or not. This is technical stuff man. Thanks Gio
With practice & experience you'll know
I can't thank you enough for these amazing series! I've been already using so much knowledge from it in my work. Huge thanks!
Super happy to hear this, thank you & keep on rocking 🙌
***SUMMARY***
- Abstract class is the class that has at least one an abstract method
- Abstract class does just declare the abstract method but does not implement it. In other terms, it knows what of the abstract method but not how of the abstract method
- Child class method knows how the abstract method
- Rule for using the abstract method:
-. The signature of the abstract method and child class method must be the same however the abstract method can have additional arguments.
I will add :
- Abstract class can have both abstract method and normal method
- Abstract method can't declare as private
- The abstract method can have additional arguments so long as they have default values.
abstract classes can implement static methods
Thank you, @Gio! I now grasp the concept of abstract classes better than I did in college.
That's great, happy to hear 💙
Great tutorial
Thank you 🙌
Hi sir
everything is just perfect and up to the mark.
just one suggestion as most of us make notes it will be very helpful if imp point you mention in between could be available as summary in one frame so that we can take snap of it rather than typing by our self.
Again thanks for what u r doing GBU🙂🙏.
Hello. Thank you & I'll try my 💙
Thank you for this! Currently watching this course everyday. Again, thank you!
You're very welcome, thanks for watching
@@ProgramWithGio I remember someone suggesting if you can create a "composer tutorial", and I will gladly support that in case you plan in creating one. Thank you again! I really appreciate it.
Thank you very much Gio 👍👍👍👍
You're welcome
Very interesting lesson, thank you
Glad you like it, thank you 🙌
This course is awesome, to say the least. Thanks!
Thank you 💙
amazing as always
Thanks 💙
Great one man!!! Really cleared a lot of things for me!
Glad to hear it, thank you
Great PHP tutorial, thank you so much!
Thank you 💙
Thank you so much Gio , I said and will keep saying that you are the best who knows everything about PHP. I have one question, is open-closed principle often used in oop or not so?
Thank you. Yes that is one of the principles of OOP in general, not specific to PHP
Thanks, well explained.
What is the major difference between Abstract and Interface?
Thank you. The next video will be about interfaces & I'll explain the differences. The main difference is that abstract class can have implementations (non-abstract methods) while interface only contains method definitions. The next video will have more details.
@@ProgramWithGio Once again thanks for the awesome tutorials
@@brainyworld2184 you're welcome. I'm glad it's helpful 🙌
@@ProgramWithGio Your clear explanation of basic concepts keep me coming for your tutorials
@@brainyworld2184 Very happy to hear that. Those basic & small details are pretty important :)
Please turn on subtitles!
thanks for the tutorials
Subtitles are on, it's just sometimes UA-cam doesn't generate them on some videos.
Thank you!!!🙏
You are welcome 🙌
Thank you.
You're welcome!
thank you!
You're welcome
Hi, isnt it overloading instead of "overriding" at 7:47? As I know, if you use same method in child class but pass different parameters, its overloading not overriding. But is it different in PHP?
Hello. PHP does not support method/function overloading. Overloading is when you have 2 functions with same name but different arguments and it gets called based on the arguments passed. When you use inheritance you are overriding the method.
why do we need to create instances of Field and Boolean and display them if we don't need them? we can as well ignore creating the instances and display the rest? i need explanation on this, thanks
Just as an example, if you watch it little bit more we change the Field & Boolean to abstract classes & remove the instantiation part.
can abstract class inherint another class as an abstract ? and another thing you say about override default values the render function in the parent class has argument which is $name.?
Yes abstract class can extend another class. I don't think I understand the question about default value, can you rephrase?
its a perfect series go ahead do u have any courses on udemy u the best
Thank you. No, I don't have courses on Udemy
Thanks again! Oh, it looks like i am the first commenter.
You're welcome :)
this is some nect level stuff
Glad you like it
I think that abstract class can also be used as a kind of documentation that is embedded directly in the code instead of writing it as comments on the code
Hmm, not exactly sure what you mean
@@ProgramWithGio
I mean that if another developer sees the code, he can, according to the abstract class, understand how the rest of the code is structured and what it means
@@user-mo3cw6go7c I don't see that as a good usecase to be honest. If you want to enforce something you can use interfaces to set a contract. Abstract class shouldn't replace a documentation then it just adds extra class for no apparent reason. Maybe I'm missing something.
Gio is so blazing fast that watching in 0.85 feels like a must 😂
😂😂. I'm so sorry haha. I've made mistakes while editing. I am usually fast while talking but I also cut out empty spaces while editing making it seem like I don't breathe 😁
Great!!!
But I don't understand why in your example we could not simply make the rendering more flexible to be used on every of the childs to reduce duplication.
public function renderField($type, $name) {
return
You could but then what if you have Select or other type of fields that are not . You'd have to override the method. So another way would be to have InputField as base class which has the render method with and then rest of the input type fields would extend this. Select field would extend the base field class & have its own render.
@@ProgramWithGio Yeah, that sounds clear to me. Indeed that is a bit what I meant. For me it sounds great to get rid of as many HTML-stuff and build my page with PHP-objects but is this really usually done or is it only a kind of playground?
It depends, if you are building some kind of library or a toolkit then maybe. I personally try to keep the UI components inside front-end & avoid using PHP for it unless I need some dynamic generation, even then I try to create an API for it so that I can pass info from PHP to view & have the view generate the proper html component
When I an trying to use the Property Promotion Attribute PHPStrom 2020.1 throws error: semicolon expected.
I have PHP8 installed locally, but can't set PHP language level above 7.4 in PHPStorm Settings.
Is there a possiblity to overcome this?
Excuse my poor english, I am Dutch :-)
PHPStorm 2020.1 does not have support for PHP 8, you will need to update the phpstorm version. It was added I think in 2020.3 or 2021.1
When to use abstract classes and when interfaces?
Next video is about interfaces and that should help answer that question. In general if you need polymorphism you would use interfaces. Abstract classes for inheritance if you need to build a hierarchy in a way
@@ProgramWithGio Thank you! Clear answer!
Hi Gio , could u turn on the subtitles for this video?
Also , did you mention the heredoc html syntax in previous videos?
It should be automatic, I'll check what's up with this video, maybe UA-cam wasn't able to detect it. There is video about heredoc syntax in first section of the course together with string data type
Hi Bro, I am still having problems with your code samples. In the previous lesson the src folder and this lesson is different. So i follow and override the old src folder. That is ok, if and only if you dont go back to the older contents at some point in another video. In some cases you do that and I had to scramble to create the old codes. I hope its going to happen again.
Some lessons don't have source code like this one. If the lesson is mostly theory then it doesn't have branch in the repository. Ones that do you will find the link in the description to the specific branch. Most lessons in 1st & 2nd sections don't have associated branches. You can always DM me on Twitter and I'll be happy to help you & clear up any confusion 👍
@@ProgramWithGio That is what I decided. Done testing code. Just watch n move on. Less leg work.
@@truthteachers yea, third section is where you'll need to code along and there are branches & source for them available.
Bro is it necessary that an abstract class should have atleast one abstract method ??
No, you can have abstract class without abstract methods. It's just if you have at least one abstract method then class has to be abstract also.
@@ProgramWithGio Sounds Nice :D
The more abstract OOP gets, the dumber I feel 😵💫
I feel you. I've felt the same way when I was starting out, so don't worry about it. Keep practicing & stay consistent and you'll get through it 💪
start 2024-03-04, today 3-19 still in here i have lot of things to know.
Keep going, its not a sprint, its a marathon. Enjoy the process