PHP traits in depth with examples - OOP in PHP | Part 9
Вставка
- Опубліковано 18 вер 2024
- In the following video, it is explained what is PHP Traits, how to create and use them.
Showing examples of:
- Multiple Traits
- Traits and inheritance
- Abstract methods in traits
- How to convert code using traits
- How Laravel uses traits
Introduction to OOP in PHP - • Introduction to OOP in...
Creating classes in PHP - • Creating classes, prop...
Inheritance in PHP - • Inheritance for beginn...
Abstract classes in PHP - • Abstract classes, abst...
Interfaces - • Interface in PHP for b...
Useful links:
www.php.net/ma...
developer.hyvo...
github.com/dwi...
blog.programst...
stackoverflow....
Follow me on social media:
/ thecodeholic
/ thecodeholic
github.com/the...
Very good, congrats.... I'm Brazilian and I liked alot your ability to teatch.
UHHHH G.. with no fear i can say that you are the best tutor ever that i ran into by far. Congrats man, keep up the good work!!!
You absolutely deserve more subscribes (y)
Thank you. It means a lot
There was a very cool example with the Avengers.Hello from Russia
Really educative. Looking forward for more vids!
Awesome tutorial. Plain should be spelt as plane.
Ups.. Thanks for noticing...
Great, simple and direct to the point. 14:38 when u said " This is absolutely valid code". i was like WHAAAAAA :D
Excited to read such comments... :D
your examples are awesome sir.....love you explanation..
Thank you
Thank you, this was really helpful, your generous hard work was appreciated. May God bless you.
Thank you
Typo: Plane, not Plain. Good video :)
Thank you Jose
Thanks to you I am watching the avengers end game again haha. That part liftTheHammer() was just amazing. Keep up the good work. Every scenario and problems using traits was well explained
Thank you. This is an awesome video course.
Thanks a lot
15:07 why there is "Hello from class AHello from trait A" not "Hello from trait AHello from class A"?
Looks like syntax error not accounting for order of execution. If the echo in the parent class is changed to a return then it will work fine.
Very good advice my friend. Thank you.
This class was great! Thanks. New subscriber.
thanks, that was helpful. traits can solve duplication and single inheritance, alright. according to your examples, i have a feeling, that you also can mess things up big time :D ... i might going to use it to deduplicate some code in models.
I have a question, interfaces also accepts multiple inheritance, so what's the difference between interfaces and traits?
Interfaces only contain the method names and signature. But traits contain method implementations as well.
Noted
I really like this video I m taking your courses to begin some design pattern I hope if you could use a module on yii on your eCommerce project it will be a great thing for now I m doing that to isolate code and doing branches with GitHub for each module separated than the other.
Nice...
perfect thanks
Thanks bro
In simple words is like a reusable component but for functions? i'm right? nice series of videos btw
For classes.
Their purpose is to achieve multiple inheritance.
@@TheCodeholic Thanks, master
6:56 I would like use abstract class or interface sir. What difference
1. Abstract classes can have implementations of the methods. However interface only defines method signature.
2. You can only extend from one abstract class, but implement multiple interfaces.
So traits in php are analogous to interfaces in java?
No.
There are interfaces in PHP also. I am not Java expert, but I think there is no analog of traits in Java.
@@TheCodeholic I've just found this question solving the problem:
stackoverflow.com/questions/9205083/traits-vs-interfaces
Thanks for the reply.
Lol I literally said out loud while I was watching this 'but you can do this with inheritance', then 2 seconds later you were like 'You might be thinking that you can use inheritance.'
That was weird lol.
Lol. I need to watch that part. Can you tell me the timecode?
@@TheCodeholic haha 2:13