14: Abstract Classes in OOP PHP | Abstract Explained | Object Oriented PHP Tutorial | PHP Tutorial

Sdílet
Vložit
  • čas přidán 8. 09. 2024
  • In this OOP PHP tutorial, I will let you know about abstract classes in OOP PHP. Abstract classes in PHP are used to help us create behavior similarly to interfaces, but they do serve a different purpose as well.
    ➤ MEET OTHER AWESOME PEOPLE!
    FollowAndrew
    Channel: / followandrew
    With over 20 years experience, Andrew is creating web & front-end design tutorial videos!
    ➤ 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 to share improved and updated lesson material, and for a small fee you can access all the material. I have worked hard, and done my best to help you understand what I teach.
    I hope you will find it helpful :)
    Material for this lesson: / lesson-material-42361704

Komentáře • 104

  • @davidsimonovic6471
    @davidsimonovic6471 Před 4 lety +42

    I would love to see a OOP PHP full site video after the oop tutorial. My morning starts with a coffe and lesson here. Keep it going.

    • @JoshuaTMagee
      @JoshuaTMagee Před 4 lety +7

      I second this, and would be more than happy to pay money for it. Ideally a full website build that includes OOP PHP coding solutions for user authentication, password recovery, user account dashboard, and shopping cart/checkout. Thank you!

    • @lebedev9114
      @lebedev9114 Před 4 lety +2

      Guys , I am also learning PHP and it is going tough for sure, but don't be deceived by videos. The videos are there to give you the theory, the concepts , but 80% of being a successful programmer is just coding on a daily basis whether it is 45 min or 8 hours , and actually do the code yourself . You can practice with simple things, eventually you will realize it is all repetitive. You don't need to a whole tutorial on building a shopping cart to build one, just start actually putting in the work..

    • @abdulrahmann1621
      @abdulrahmann1621 Před 4 lety +2

      @@lebedev9114 Hey bro do you ever know why the extends thing is not working ? when i make a class for example and then make another class and extends from the first class in another file it's giving me an error if i don't include the file of the parent class in the file of the second class>>> without including the file it's not extending any thing!!

    • @lebedev9114
      @lebedev9114 Před 4 lety

      @@abdulrahmann1621 bro check the autoload tutorial and make sure you made it correctly. Otherwise each time you make a new class file you have to use 'include' function to include the other class you plan to extend.

  • @MuhammadAli-ve7mt
    @MuhammadAli-ve7mt Před 2 lety +4

    I'm going to leave this here in case someone finds the use of abstract classes confusing even after the explanation.
    Consider an abstract class for an Employee. Each employee is going to have common attributes such as first name, last name, address and so on, but there will be some attributes that differ.
    Now, let's say we are talking about an educational institution. There can be "permanent" or "visiting" employees. Permanent employees get paid an equal amount every month, so their salaries can be defined in their own "PermanentEmployee" class which extends the main "Employee" class. And for visiting employees, the salary can be defined in a class called "VisitingEmployee" which also extends the main Employee class.
    abstract class Employee{
    protected $firstName;
    protected $secondName;
    protected $address;
    }
    class PermanentEmployee extends Employee{
    private $salary;
    }
    class VisitingEmployee extends Employee{
    private $hourlySalaryRate;
    }
    In this way, we get to use the common attributes through the child class, as well as attributes of their own.

  • @stormybear4986
    @stormybear4986 Před rokem +1

    I love Dani's tuts because he speaks a neutral dialect of English (so many computer tuts come out of India and the people speaking have a very poor grasp of English and they are too difficult to uunderstand) and he gives very helpful info. Dani is one of the best channels on youtube for programming!

    • @Michael-lo3ht
      @Michael-lo3ht Před 7 měsíci

      Totally agree. They also speak English at the same speed they're used to speaking. So it's impossible to understand all the words. On top of that, trying to pick out technical details multiply the problem. This is one channel I am hooked on.

  • @andreitodosi
    @andreitodosi Před 4 lety +44

    Always wandered what the Peaky Blinders are up to these days..

  • @bgray79
    @bgray79 Před 4 lety +8

    I just discovered that the order in which classes are included is important. I haven't heard you mention that yet. It took me a few minutes to figure out why I was getting an error, as I had been using a separate header, index, footer page. After reducing it down to what you have here, I still got an error stating that the "Visa class could not be found referenced in BuyProduct". Then I moved the include abstract statement to the top, and voila! It works.

    • @derpspopovich1579
      @derpspopovich1579 Před 4 lety

      oh fk thanks for this.been trying to solve this error for a minute. the include abstract statement should be first at the top.

    • @ozanulutas3334
      @ozanulutas3334 Před 3 lety

      That's because the computer read the codes from start (top of the file) to finish. If you woludn't include the abstract classes -which will be used(extended) later- first it throws an error about not finding the referenced class.

    • @samduss4193
      @samduss4193 Před 2 lety

      if need to setup them are required or what s going to happen with autoloader :) .... Let see one step at a time :) this is coding hahah

  • @onee
    @onee Před 2 lety +7

    If you're wondering what abstract classes are (like me), and WHY we use abstract classes, go to 8:41. I've been looking up and down the internet for someone to explain this in simple words to me, and finally found it. For some reason the other people I stumbled upon all make it unnecessarily overly complex. Especially if they intend to teach this to beginners.

  • @wadiibounenni4848
    @wadiibounenni4848 Před 6 měsíci +2

    Deep Theory + Practical Life Examples + Clear Explantations = Dani :)

  • @jaicarter6337
    @jaicarter6337 Před 4 lety +2

    I've watched both your PHP playlists and followed every step - it's really helped me understand PHP on a better level than sites like Codecademy thanks bud!

  • @asuUcKa
    @asuUcKa Před 4 lety +1

    Wow 3 days of school = 1 of your videos, (i need to put more attention to class) but i learn better here.

  • @m_lk9434
    @m_lk9434 Před 4 lety +1

    Started watching your videos to learn a few concepts that i was uncertain of. And now im watching all the videos just because I love they way you speak😂😂❤️
    But I must appreciate, the explanation is convincing, they way you present the content is awesome. Good luck❤️

  • @binsarharseno
    @binsarharseno Před 4 lety

    I think by just listening your explanation like a podcast i will understand what is abstract class is, very clear, thank you

  • @stormybear4986
    @stormybear4986 Před rokem

    Dani for a person whose first language is not English, you have really a masterful command of the language. Your accent sounds very natural, i think you must've spent a lot of time in the USA to master our crazy accents. I was an ESL teacher for many years and I wish I could bottle your accent and give it to my students. How long were you in the USA and what part of the country? I'm guessing the midwest or California.

  • @bilalbeny4172
    @bilalbeny4172 Před 7 měsíci +1

    thank you for this amazing video :), I love your way in explanation and simplify things, keep going🙏

  • @user-kh1ef3sz4b
    @user-kh1ef3sz4b Před rokem

    this course is amazing, amazing teacher. And also its a strange feelin to learn all of this from Ellon Musk. HAHAHA just kidding, thank you a lot for all of this classes. Really helped. The world need people like you!

  • @RahmanHaghparast
    @RahmanHaghparast Před rokem +1

    Simple and well explained. Thanks.

  • @dzintarsmagons
    @dzintarsmagons Před 4 lety +1

    Thank you for the effort that you put in making these videos. Your way of clarifying things makes this way easier.

  • @OPGAMER.
    @OPGAMER. Před 3 lety +2

    Really Good Idea of Naming Files!!! I will Follow this!!

  • @4english21
    @4english21 Před 4 lety +1

    you'd be my favorite teacher. the way you explain stuff is so clear and that's perfect, maybe i couldnt say the same for the examples though. keep up the good stuff anyway.

  • @alexlytle089
    @alexlytle089 Před 2 lety

    Finally a clear explanation of abstract classes

  • @Born2DoubleUp
    @Born2DoubleUp Před 2 lety

    I'm here! 😎 Great video, just posting a comment to show some support! Keep up the good work. 🤙

  • @lpanebr
    @lpanebr Před rokem

    Just like the interfaces video, this is great! Clear explanation with real world use case. Thank you!

  • @vlatkoviamkd
    @vlatkoviamkd Před 4 lety

    This is the first video that i have seen from you but the way you explain things are one of the best i have seen and i have been watching many of Udemy and youtube courses . Respect, keep on the good work. Subscribed

  • @naganorthwind
    @naganorthwind Před 4 lety +2

    Very precisely elaborated. Would like to see laravel tutorial too. Thank you

  • @SherwinlouwZa
    @SherwinlouwZa Před 3 lety

    the best oop php tutorial I've come across. Clarity!!!!

  • @earlempic3983
    @earlempic3983 Před 2 lety

    One other thing that you can do in extending class is you can play the callback like in BuyProduct Class
    public function visaPayment(){
    $callback = parent::visaPayment();
    $callback.= " from buy product."
    return $callback;
    }
    output will be "Perform a payment from buy product."

  • @user-he6xf1zr5e
    @user-he6xf1zr5e Před 9 měsíci +1

    Thank you so much for making this video.

  • @lauramazariegos6412
    @lauramazariegos6412 Před 2 lety

    Thank you for a great explanation! That really cleared up the fuzzy pieces for me on abstract classes and their application.

  • @LostAlienOnEarth
    @LostAlienOnEarth Před 7 měsíci

    Some important rules:
    1. One class can extend only one abstract class (PHP doesn’t support multiple inheritance).
    2. Any class with at least one abstract method must be declared abstract.
    3. Abstract classes might contain concrete methods (rules or logic already implemented), interfaces don't have any implementation (it is just a prototype declaring the signatures of the methods - return type, parameters), it's just a contract that must be followed by implementing classes which will supply its own implementation.

  • @siyaramgungan
    @siyaramgungan Před 2 lety +1

    I really love all videos and the method used to teach, Great job Bro

  • @odunladeoluwaseun7880
    @odunladeoluwaseun7880 Před 5 lety +1

    Nice tutorial on abstract. thanks for the usually quality delivery. please I need a revision on using traits

  • @ademineshat
    @ademineshat Před 5 lety +4

    Will we build some kind of Project including things we've learned?
    Anyway thanks
    Edit: Best video sofar including Voice quality, video and how you placed the things :)

  • @Michael-lo3ht
    @Michael-lo3ht Před 7 měsíci

    I love the videos. I will have to digest more of the interfaces again, as it took too many turns and twists later and lost me. I have to say I'm totally lost on this one. I guess when I hear abstract I guess I expected the names to be abstract or something. So far it just only looks like you extended a class. I will have to maybe find something that might fill in the blanks for me. Sorry, that I didn't quite pick it up for some reason.

  • @zedshaw7275
    @zedshaw7275 Před 4 lety +2

    That was an awesome set of videos. I learned a lot from you thank you.

  • @jeesambo
    @jeesambo Před 4 lety +1

    Thank you so much. Your presentation is extremely perfect. thanks alot for the tutorial. Fly high.

  • @AbhishekBiz
    @AbhishekBiz Před 4 lety

    Dude you have the great style of coding and fashion both.

  • @acavaelnick
    @acavaelnick Před 4 lety +1

    Great series of videos dude!
    Really helping me out to understand this concepts, thank you so much!

  • @TahirBhai
    @TahirBhai Před 3 lety

    Good to see a detailed OOP series in PHP with awesome real life examples. Thank you @Dani Krossing

  • @localLyricsPh
    @localLyricsPh Před rokem

    The best lessons dani keep it up. I really prefer this youtube because it's free and well explained. 💞💞

  • @NawarZarif
    @NawarZarif Před 3 lety

    Very nice presentation.thanks

  • @generalpolkovnik4039
    @generalpolkovnik4039 Před 5 lety +1

    thank you all your videos helped me

  • @tryharder927
    @tryharder927 Před 5 lety +1

    i will watch all of your videos
    love it man

  • @raulrojas6552
    @raulrojas6552 Před 2 lety

    Easy and for the whole family

  • @arshiatolou1958
    @arshiatolou1958 Před 2 lety

    tysm for this great content Mr.Dani !

  • @nikolav6350
    @nikolav6350 Před 5 lety

    THANK YOU FOR THIS OPP LESSONS YOU ARE THE BEST!

  • @palyons4817
    @palyons4817 Před 4 lety

    You're videos have been a great help, many thanks!

  • @adilsaeed5381
    @adilsaeed5381 Před 4 lety +1

    Uncaught Error: Class 'visa' not found in C:\xampp\htdocs\oop\classes\buy.abstract.php:4 Stack trace: #0 C:\xampp\htdocs\oop\abstrction.php(2): include() #1 {main} thrown in C:\xampp\htdocs\oop\classes\buy.abstract.php on line 4
    whts the solution i did the same code only names are diffr

  • @rimantasdanilevicius6754
    @rimantasdanilevicius6754 Před 3 lety +1

    Can we say that abstract and interface almost do the same? I think I see that we can do the same with interface and interface more useful. Because what if you had more classes which contains other payment types like Paypal? Does it mean I need to create another abstract class for Paypal and extend it in new byproduct class? It is already sounds confusing :D
    Very clear communication.

  • @TommyTompkins
    @TommyTompkins Před 2 lety

    Is it possible to have a method in your abstract class that calls an abstract function that is implemented in the child class? I'm trying to do this but keep getting errors.

  • @tuananhdo1870
    @tuananhdo1870 Před 4 lety +3

    Could you make tutorial on namespace in PHP?

  • @gtggj6851
    @gtggj6851 Před 4 lety

    You can run most of examples in the windows console using php - f name.php .

  • @ProgrammingwithPeter
    @ProgrammingwithPeter Před 5 lety

    Your tutorials are great, flawless !

  • @98toxic1
    @98toxic1 Před 5 lety

    You're the man! Thanks for all you do!!

  • @dinushasathyajith5049
    @dinushasathyajith5049 Před 5 lety

    Great video. Thanks Daniyel 😁😁

  • @patrik5123
    @patrik5123 Před 3 lety

    Why do some insist on never wrapping include or include_once with parenthesis? I mean, it's a function, so it looks more correct as include('file.php');

  • @tuncaybasak4953
    @tuncaybasak4953 Před 4 lety

    So, in the MVC design pattern the MODEL class is declared with ABSTRACT? (as it is only extended by VIEW and CONTROL classes and never called by a constructor)

  • @josemfcheo
    @josemfcheo Před 4 lety

    Thanks man!

  • @Urti
    @Urti Před 4 lety

    You are great ! please create laravel course.

  • @stormybear4986
    @stormybear4986 Před rokem

    Dani, how did you learn PHP to such a high level?l I studied software engineering in college and I don't have the level of mastery of PHP that you have.

  • @roiunger7796
    @roiunger7796 Před 5 lety +1

    Beautiful hat my brother

  • @RK-gm4pd
    @RK-gm4pd Před 5 lety

    Great video. Thanks to author!
    All these OOP it's just total mess and gibberish. I never understood why people invent tons of unnecessary rules and frames for it's life. JS forever! Only prototype ))

    • @daniele5692
      @daniele5692 Před 4 lety

      «I never understood why people invent tons of unnecessary rules and frames for it's life»
      yes, JS hasn't unnecessary rules....

  • @Maccelerate
    @Maccelerate Před 5 lety

    Great video!

  • @Oxmond
    @Oxmond Před 5 lety +1

    Good job! 👍 && hat == "awesome"

  • @CastleShield
    @CastleShield Před 2 lety

    You look like a movie star on a vacation in Europe with that hat and glasses.

  • @YCode_
    @YCode_ Před 5 lety

    gooood job thank you

  • @jasminepleass3818
    @jasminepleass3818 Před 2 lety

    If you're coming across an error 'Uncaught Error: Class 'Visa' not found' include 'include(__DIR__ .'/../abstract/paymenttypes.abstract.php');' in your BuyProducts.class.php, no need to include this on the index page also.

  • @abdulrahmann1621
    @abdulrahmann1621 Před 4 lety

    hello mmtuts do you ever know why the extends thing is not working ? when i make a class for example and then make another class and extends from the first class in another file it's giving me an error if i don't include the file of the parent class in the file of the second class>>> without including the file it's not extending any thing!!

  • @karthickm2623
    @karthickm2623 Před 4 lety

    What suppose multiple class I need use abstract class "implement" not required here ?

  • @jkrmarmol
    @jkrmarmol Před 2 lety

    you look like Elon Musk haha btw thank you so much your video are very helpful to me

  • @kushalchavan1
    @kushalchavan1 Před 5 lety

    Please start tuts on php laravel coz we love your explaination 😉 thanks for awesome videos

  • @oghenevwefepeace2501
    @oghenevwefepeace2501 Před 2 lety

    Please how do i run mysql logics with getters and setters

  • @augischadiegils.5109
    @augischadiegils.5109 Před 3 lety

  • @danielmobbs5096
    @danielmobbs5096 Před 4 lety

    love the hat!!! :D

  • @kubulus7868
    @kubulus7868 Před 5 lety +1

    do you use php on the daily basis? I ask, 'cause php is gradually being replaced by node and other js things.

    • @kubulus7868
      @kubulus7868 Před 4 lety

      @@jasondavies3772 Yeah I do, and I am even on php side, but I just noticed this trend

  • @anewworld5201
    @anewworld5201 Před 4 lety

    Which is base class and derives class

  • @youssefdaoud7265
    @youssefdaoud7265 Před 5 lety +2

    Mmtuts can you please create a customer queing system

  • @nick9198
    @nick9198 Před 3 lety

    nice hat bro

  • @siriusgd4753
    @siriusgd4753 Před 4 lety +1

    I still get confused as to how an abstract class is any different from a simple extended class.

    • @dusanknezevic4028
      @dusanknezevic4028 Před 4 lety +3

      The functionality is basically the same, however as explained in the vid the main difference is that abstract classes and functions/methods can't be instantiated (you can't create the objects from them like you can from regular ones). You can think of it as a chunk of a common reusable code that you never gonna use on its own, but only as a substrate or a base class to extend to your other classes that all should extend the properties and methods from this abstract one.

    • @abdulrahmann1621
      @abdulrahmann1621 Před 4 lety +1

      @@dusanknezevic4028 Hey bro do you ever know why the extends thing is not working ? when i make a class for example and then make another class and extends from the first class in another file it's giving me an error if i don't include the file of the parent class in the file of the second class>>> without including the file it's not extending any thing!!

  • @nahabat9
    @nahabat9 Před 5 lety +1

    please make a laravel series!!!!!!!!!

  • @bobz2169
    @bobz2169 Před rokem

    08:26

  • @perianka
    @perianka Před 4 lety

    where are you from?

  • @dhrubavideos
    @dhrubavideos Před 4 lety

    U very cleverly just touched it but not elaborated with example

  • @benjamindavies7113
    @benjamindavies7113 Před 2 lety

    You look like Elon Mask with that hat 😀

  • @king_israel6
    @king_israel6 Před 5 lety

    Nice hat and video but please I need a huge favor from you😭😭😭

    • @roiunger7796
      @roiunger7796 Před 5 lety

      Is everything all right? Maybe I can help you?

    • @king_israel6
      @king_israel6 Před 5 lety

      @@roiunger7796 OK I wanted some favour like how to add download link to files and also the php comments video have a little goof. The comments didn't enter the database then again I wanted a pagination page with links😭😭

  • @tomatomov9061
    @tomatomov9061 Před 2 lety

    Yet another tutorial showing absolutelly basic usage of abstraction. And 99% will ask themself why would they need abstract classes at all. Will downvote it because you people just copy each other content.

    • @Dani_Krossing
      @Dani_Krossing  Před 2 lety

      There are a couple of things I'd like to address in regards to your comment...
      Firstly, I'm going into great detail in my video to explain what abstract classes are and how they work. And accusing CZcamsrs who are only here to try and help you, of "just copying each others content", is both disrespectful, and an INCREDIBLE entitled behaviour towards FREE content.
      This link took me 10sec to find on Google, which explains examples of abstract classes and when to use them in detail: www.quickstart.com/blog/when-and-how-to-use-abstract-class-and-interface/
      The issue here is not "CZcamsrs being lazy by copying each other". It's you looking in the wrong places or not understanding it when you find what you were looking for, and then taking your frustrations out on CZcamsrs who provide you with FREE educational content.
      You didn't pay for a Udemy or Lynda course... You are here on CZcams watching FREE content. You are grossly misunderstanding what "rights" you have, when you are trying to 'smite' a content creator who provides FREE educational content.
      I recommend going to a paid service like Udemy, since over there you ACTUALLY have the right to complain about it not being good enough for you.
      If I see another entitled comment from you, I will block you.

  • @myvishan
    @myvishan Před 4 lety

    PRO TIP: turn the video at x1.25 speed. Thank me later.

  • @cd78
    @cd78 Před 5 lety +1

    OOP = overly convoluted nonsense. Learn procedural instead..