PHP - Inheritance Explained - Is Inheritance Good? - Full PHP 8 Tutorial

Поділитися
Вставка
  • Опубліковано 8 лис 2024

КОМЕНТАРІ • 143

  • @johongirrahimov2343
    @johongirrahimov2343 3 роки тому +38

    So from now on till the end of the lesson, I try to summarize what I've learned:
    - We can access public & protected properties, constants, and methods of the superclass in subclass
    - To override public & protected properties and constants of the superclass, we've to use the same or higher visibility
    - Constructor methods are optional, they are called in the background(In JavaScript as well)
    - To override the constructor method of the superclass, we have to call "parent::__construct()" with all necessary arguments required in the superclass' constructor method.
    - To override public & protected methods of the superclass, method signature which is argument type, argument amount, and return type must be the same (this does not apply to constructor method).
    - To create a constructor method in a subclass, we don't have to also create a constructor method in superclass
    - We can use inheritance when class has is-a relationship
    - When class has has-a, can-do relationship then we should use composition

    • @ProgramWithGio
      @ProgramWithGio  3 роки тому +9

      Great summary 👏. One correction, to override parent's constructor you don't need to call parent::_construct, you need to call parent construct if you want to run parents constructor when you override the constructor method. Good job 👍

    • @johongirrahimov2343
      @johongirrahimov2343 3 роки тому +6

      @@ProgramWithGio Yeah got it dude, thanx for correcting me

    • @ahmedats335
      @ahmedats335 3 роки тому +7

      Dude, this is an amazing summary, thank you so much, keep it up. :D
      I'd like to add this - The constructor of the child class doesn’t automatically call the constructor of its parent class.

  • @federicobau8651
    @federicobau8651 2 роки тому +21

    Best PHP and complete course. Better than many paid bootcamps and best quality

  • @ProgressiveDeveloper
    @ProgressiveDeveloper 7 місяців тому +1

    This tutorial is more than just advanced and comprehensive. I am using it even in my Python journey. Thanks, GIO❤

  • @Zubbee
    @Zubbee 2 роки тому +10

    Great lesson. The number of lessons I know I have to revisit are increasing. I'm grateful to be learning php like this with this kinds of resources available. Thanks Gio

    • @ProgramWithGio
      @ProgramWithGio  2 роки тому +2

      That is perfectly normal, glad you like the videos, thank you

  • @jemaleakil7620
    @jemaleakil7620 2 роки тому +8

    I wish I could subscribe ten times to this channel...
    Thank you so much for providing this amazing tutorial

  • @godmansarah
    @godmansarah 2 роки тому +2

    Love the Toaster, Toaster Pro, and Toaster Pro Pro illustration. So simple and clear :)

  • @dev_troy8903
    @dev_troy8903 9 місяців тому +1

    I have studied OOP using java in the past, and all I can say, hats off to you Gio. 👏

  • @Vitalii-m6r
    @Vitalii-m6r Рік тому

    There are a dime a dozen channels for learning PHP, but this one is the best! Thank you!

  • @chenting71
    @chenting71 2 роки тому +1

    25minutes video, I did it for one hour and a half (didn't get the composition yet). Great tutorial !

    • @ProgramWithGio
      @ProgramWithGio  2 роки тому

      Nice work, thank you. We cover composition in 3rd section so you'll get there in time.

  • @sfa327
    @sfa327 Рік тому +1

    This is the best course in php

  • @imanol4468
    @imanol4468 5 місяців тому

    👏👏👏 Thank you, Gio. You're the best teacher!!!

  • @invgreat5608
    @invgreat5608 2 роки тому +3

    Superb job explaining! Thank you!!

  • @lotuslando1994
    @lotuslando1994 9 місяців тому

    I just wanted to add my thanks to the long list of thank yous. 🙏
    I completed your functional PHP course (Lesson 1) about a year ago, and then immediately tried to start Lesson 2.
    Because I knew nothing about Docker, I had to take quite a bit of time off to play around with that first. Conceptually, I understand Docker, but still struggle setting up a dev environment with it.
    Thankfully, you have provided the necessary instructions. I realize you are not teaching a Docker course here! It's just what makes most sense to use in this context.
    As I'm basically a noob when it comes to programming, I found Lesson 1 to be quite challenging. But I was able to complete the final project, albeit it was not as elegant a solution as yours.
    Lesson 2 feels like it's so many more levels above Lesson 1, and not really a continuation. I feel that if I knew at least one other programing language, especially an object oriented one, I would be following along with ease.
    Instead, I'm finding it all quite challenging conceptually. I'm re-watching the videos multiple times. I type out all the code you're showing and test everything. I really am struggling to retain and understand how all these parts fit together. I'm nowhere near the project part yet, but I really do wonder if I'll be able to actually do it. There seems to be so many other things, outside of PHP, that I need to understand first.
    I'm going to keep persisting in the hopes that maybe it will all start to make sense at some point. This is not a critique of your teaching style whatsoever, which is very, very good.
    It's more a statement about me having a lack of programming fundamentals to be able to shift to this object oriented world.
    With regards to the current video, I really liked that you used Toasters as an example to explain inheritance. This non-abstract approach made the inheritance concept much easier to understand! 👍 🍞

    • @ProgramWithGio
      @ProgramWithGio  9 місяців тому

      First of all, great job on completing the first section. Second & third sections are harder for sure. The docker video & the docker in general is not a requirement. You can keep using XAMPP and follow along with it, I just used Docker as an alternative so that way I could cover nginx/fpm as well since in first section we did apache.
      If you feel like you may have a gap somewhere in between videos, stop the videos, do research (e.g. read docs, articles, try it out) & practice. You won't retain knowledge by watching tutorials if I'm being honest, most knowledge is retained after trying to work with it, break it, fix it, practice, etc.
      Feel free to ask any questions along the way, happy to help & clarify where needed. You can reach me at Twitter (X)

  • @tolebiGamingTime
    @tolebiGamingTime Місяць тому +1

    Cool course, I'm waiting for the video lesson on microservices)

  • @jeevachaithanyansivanandan
    @jeevachaithanyansivanandan 3 роки тому +5

    very well explained. thank you

  • @janwan
    @janwan 2 роки тому +1

    I really like your tutorials. It's really a refresher for me.

  • @ferdinandeke9590
    @ferdinandeke9590 3 роки тому +8

    Hey man, thanks a bunch for your insightful tutorials..the contents here are really helpful.. I'm an advance php-laravel developer though from a Java background, but honestly I felt the need to learn php from scratch again cos I love the approach you adopted, really in-depth, and I'll be on ur channel a lot to see contents in the future.. cos I look forward to learning Laravel indepth the way you treated php, cos I just know how to implement my tasks and get my applications running on Laravel but I felt the burden to really understand the concepts in detail, cos it's quite a lot on Laravel and I just know how to do stuffs but don't have a sound understanding of a lot of terminologies, for instance I took a dev stack test, php-laravel, I passed the php and then failed Laravel which I was a lot easier but certain terminologies just confused me and funny enough I knew the answers but couldn't relate them to the best fit for the questions... So I hope to see a lot more of you contents.. Many thanks to you..

    • @ProgramWithGio
      @ProgramWithGio  3 роки тому +10

      Thank you so much. There will be a lot more content including Laravel once I'm done with this course. I put a lot of effort in each video regardless of how easy the topic is. I try to teach it the way I would want to learn it myself. A lot of times small details are left out from tutorials that leave me confused, so that is the gap in trying to fill. That is why sometimes it takes me awhile to publish a video.

    • @ferdinandeke9590
      @ferdinandeke9590 3 роки тому

      @@ProgramWithGio I also started off teaching my colleagues programming at the office, trying to build a team of my own, so I'll be referring each and everyone of them to you channel to join in and be part of this channel.. warm regards!

    • @ProgramWithGio
      @ProgramWithGio  3 роки тому +1

      @@ferdinandeke9590 thanks alot. I appreciate it 🙏

  • @elizabethsullivan1894
    @elizabethsullivan1894 Рік тому +1

    This is incredibly useful! I've been doing some Python just to automate some tedious tasks, but I wanted to learn PHP to make a web-based tool. Even though the syntax is different, it's interesting how much of this course also translates over to Python and to the VBA I use sometimes in my job.

  • @parinataneja7099
    @parinataneja7099 2 роки тому +1

    Hi again, thanks Gio :) I am learning so much new stuff from this tutorial. Keep Rocking!

  • @ilya_123__
    @ilya_123__ Рік тому

    Step by step i trying to finish this course :)

  • @PaulNike
    @PaulNike 3 роки тому +5

    Thanks! Very helpful video

  • @michaelerwin8744
    @michaelerwin8744 Рік тому

    I think 21:21 is a good example of inheritance related issue and explains well the application of Liskov Substitution Principle.

    • @ProgramWithGio
      @ProgramWithGio  Рік тому

      Yup, we cover composition as well in the series

  • @superheroshortss
    @superheroshortss Рік тому

    Great Explanation. Love it Gio

  • @karam0101
    @karam0101 2 роки тому +2

    Amazing as usual, thank you very much

  • @aleksandrkanygin2672
    @aleksandrkanygin2672 2 роки тому +2

    Great tutorial as always

  • @memack101
    @memack101 2 роки тому +2

    Thank you.

  • @keremardicli4013
    @keremardicli4013 Рік тому

    Simply perfect 😮

  • @muditgulgulia5350
    @muditgulgulia5350 2 роки тому +2

    Found this course while revision all my logic, and thinking why it was not available 3 years back.
    Great Content!

  • @chadcglk7951
    @chadcglk7951 2 роки тому +2

    It would be great to see vanilla php app tutorial, see all these concepts in action.

    • @ProgramWithGio
      @ProgramWithGio  2 роки тому +1

      We'll work on an app at the end, though I'm still working on figuring out the details but it won't be fully vanilla since we'll be using some packages.

  • @udayan285
    @udayan285 Рік тому

    Thank you Gio.

  • @simplecad7462
    @simplecad7462 Рік тому

    Great tutorial! Using terminal instead of localhost page makes debugging much faster and takes less space from screen. I found out for vscode + docker i have to type "docker exec (container id) php src/public/index.php" to run index.php file inside terminal.

  • @emekatimothyiloba699
    @emekatimothyiloba699 Рік тому

    Thank you Gio

  • @omaryahia
    @omaryahia Рік тому

    your explanations are sooo amazing , love your videos man, thank you soo much❤🌟

  • @rustem6388
    @rustem6388 Рік тому +1

    Thank you!!!🙂

  • @mahdou3608
    @mahdou3608 2 роки тому +1

    greate course thanks a lot

  • @JustMeItsMMN
    @JustMeItsMMN 7 місяців тому

    Thank you so much bro

    • @ProgramWithGio
      @ProgramWithGio  6 місяців тому +3

      Yup, I'm working on Laravel course

  • @donmikele07
    @donmikele07 Рік тому +1

    Thanks!

  • @techatival
    @techatival 3 роки тому +4

    Again a great video.

  • @ДухДмитро
    @ДухДмитро 3 роки тому +1

    great work

  • @santvar380
    @santvar380 2 роки тому +1

    Excellent job, could you be so kind and share the composition video link?

    • @ProgramWithGio
      @ProgramWithGio  2 роки тому +1

      Thank you. There is a link to the course outline in description, you can find all lessons here: github.com/ggelashvili/learnphptherightway-outline

  • @bulent2435
    @bulent2435 Рік тому

    great work, thanks.

  • @WhiteSiroi
    @WhiteSiroi 2 роки тому +1

    love it

  • @z3ko
    @z3ko 3 роки тому +1

    Hello again :) great work. In the last part (FancyOven implementation) when you pass Toaster object thru constructor is that considered Dependency Injection?

    • @ProgramWithGio
      @ProgramWithGio  3 роки тому +1

      Hello & thank you 🙌. Yes that's dependency injection. There will be a lesson about dependency injection in 3rd section where I'll go in more detail.

    • @z3ko
      @z3ko 3 роки тому

      @@ProgramWithGio Nice, thank you

  • @goal_post24
    @goal_post24 3 роки тому +2

    again it's real helpfull

  • @AMoktar
    @AMoktar Рік тому

    Thanks ❤

  • @chenting71
    @chenting71 2 роки тому +2

    Finally got the composite works:
    class Gun
    {
    public $a = 1;
    public function foo(){
    echo 'shoting bullets ---------->>>>>>';
    }
    }
    // build a tank with method foo() belongs to Gun (shooting out something)
    class Tank
    {
    public Gun $shot; // or you can omit, or make it private(see bellow)
    public function __construct(Gun $shot) // take in another class as parameter
    {
    $this->shot = $shot; // initialise $shot and give it property name shot
    }
    public function shotGun(){ // give a public function to all shot->foo(),
    $this->shot->foo(); // in case you made shot property private(see remark line 1)
    }
    }
    $b = new Tank(new Gun); // give Gun $object as parameter - composite😁 another class
    $b->shotGun(); // use local method (inside it calls method of class belongs to other)
    $b->shot->foo();

  • @mimoh2000
    @mimoh2000 2 роки тому +1

    Hi, just a quick one . Trying out the Debt collector and CollectionAgency example. Both are in the same App namespace. Running individual scripts are ok. But when I try to implement the DebtCollector,. Am getting "Interface App\CollectionAgency not found in src/app/DebtCollector. But thinking DebtCollector should be the interface. Does interface require any modifications to the autoload to work.

    • @ProgramWithGio
      @ProgramWithGio  2 роки тому

      Hello. It shouldn't, send me screenshots of your code on Twitter and I'll help troubleshoot it

    • @mimoh2000
      @mimoh2000 2 роки тому

      @@ProgramWithGio Thanks. Just found out that PHP cli doesn't resolve autoloads with interfaces. Runing "php CollectionAgency.php" throws an error. But running "php DebtCollector.php" works find. I did implement the collection() function "
      class CollectionAgency implements DebtCollector
      {
      public function collect(float $ownedAmount): float{
      return 2.0;
      }
      }
      Then on the index.php, I created an instance of the CollectionAgency, viola everything works.
      $clAg = new CollectionAgency();
      var_dump($clAg);
      Result:
      object(App\CollectionAgency)#3 (0) { }
      Please another question is why the #3 ?. Thanks

    • @ProgramWithGio
      @ProgramWithGio  2 роки тому +1

      @@mimoh2000 ​ ah I see, yes because autoloading is not enabled in those files. Autoloading is added in index.php as in the video & in CLI you should just run php index.php.
      #3 is the object identifier.

  • @ינוןאלבז-כ1ז
    @ינוןאלבז-כ1ז 2 роки тому

    High level!!!

  • @bhaidar
    @bhaidar 3 роки тому +3

    Hi Gio, I noticed we access the parent methods using :: as if the parent methods are static. Why is that? Thanks

    • @ProgramWithGio
      @ProgramWithGio  3 роки тому +1

      Hey Bilal. Scope resolution operator '::' is not only for statics. From the PHP docs: "The Scope Resolution Operator (also called Paamayim Nekudotayim) or in simpler terms, the double colon, is a token that allows access to static, constant, and overridden properties or methods of a class." www.php.net/manual/en/language.oop5.paamayim-nekudotayim.php
      Here is an example to illustrate why:
      Class A {
      public function foo() {...}
      }
      Class B {
      public function foo() {
      // this will cause recursion & will keep on calling method foo on class B. What developer meant was to execute method foo on parent class so you use parent::foo()
      $this->foo();
      }
      }

    • @bhaidar
      @bhaidar 3 роки тому +1

      @@ProgramWithGio Thanks Gio. As usual very useful video

  • @journeytocoding816
    @journeytocoding816 2 роки тому +1

    Hello Gio, Thanks for another great tutorial. My question is if I want to make multi login in a website with logins (admin, Seller, Customer) .should I make base class as user, then class admin ,then class Seller, Then class Customer?? I haven't made anything yet just asking as curiosity.

    • @ProgramWithGio
      @ProgramWithGio  2 роки тому

      That's one way but a better way would be to have User class and use permissions/roles to control what kind of access user has.

    • @journeytocoding816
      @journeytocoding816 2 роки тому

      @@ProgramWithGio thankyou Gio.

  • @goal_post24
    @goal_post24 3 роки тому +3

    great video all wishes to you brother:(

  • @badevent
    @badevent Рік тому

    Awesome! I love, mate!

  • @Armando-px8hi
    @Armando-px8hi Рік тому

    The best, I am not gonna talk long! Just one question Gio please, as you said one of the bad things of inheritance is that the child class will inherit all the properties and methods that are public or protected, so if we do not need them to be inherited can not we just define the final keyword or it still will be inherited just we would not have an access to them?

    • @ProgramWithGio
      @ProgramWithGio  Рік тому

      Final prevents method overriding, but your child class can still call the parent method, so that's what I mean by inheriting properties & methods

    • @Armando-px8hi
      @Armando-px8hi Рік тому

      @@ProgramWithGio Got it, thanks 🙏

  • @Em1lka_
    @Em1lka_ 11 місяців тому

    Hello Gio!
    I would like to know if there is any point in solving problems using codewars? They are just difficult and I am not sure that I will get important knowledge from there. I would like to hear your expert opinion!

    • @ProgramWithGio
      @ProgramWithGio  11 місяців тому +1

      It's good to practice some skills but I don't think it's something you would use on your day to day job. It's good to pass some time & practice some skills depending on what type of challenges they have but I would spend more time building real things, that will give you the most practice & practical experience

    • @Em1lka_
      @Em1lka_ 11 місяців тому

      @@ProgramWithGio Thank you 🙏

  • @lynic-0091
    @lynic-0091 Рік тому

    I have one question, why didn't you move the toast and toastBagel methods to a Traits / Concerns folder, and named the trait something like CanToast.php ?
    Then those methods also could've been reused in the FancyOven class, without inheritance, by using that CanToast trait.

    • @ProgramWithGio
      @ProgramWithGio  Рік тому +1

      We could but this was lesson about inheritance. Also note that traits should not be used to define a contract, ideally it would be a combination of interfaces + traits or simple composition (which we cover later in the series & is also shown at the end of this video), but this lesson was just about inheritance.

  • @johongirrahimov2343
    @johongirrahimov2343 3 роки тому +3

    I've written everything the same including the folder structure but PHP throwing following error:
    Fatal error: Uncaught Error: Class "App\Toaster" not found in /var/www/App/ToasterPro.php:9 Stack trace: #0 /var/www/public/index.php(8): require_once() #1 {main} thrown in /var/www/App/ToasterPro.php on line 9

    • @ProgramWithGio
      @ProgramWithGio  3 роки тому

      Most likely it's the issue with autoloading. Share your composer.json contents & public/index.php. Also run composer dump-autoload or composer install

    • @johongirrahimov2343
      @johongirrahimov2343 3 роки тому

      @@ProgramWithGio
      I tried to run composer dump-autoload and composer install but it's still throwing the same error as in my comment. It'd be amazing if you could help me fix issue
      file
      {
      "require": {
      "ramsey/uuid": "^4.2"
      }
      }
      file

    • @johongirrahimov2343
      @johongirrahimov2343 3 роки тому

      @@ProgramWithGio And additionally in
      file. this function is underlined with red line indicating it has issue and when I hover over this function it's saying, Undefined function.
      It is in line 31 in my Code Editor.
      $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());

    • @ProgramWithGio
      @ProgramWithGio  3 роки тому +1

      You are missing the autoload option in the composer.json. I put the exercise & project source in github, you can take a look at the composer.json file there. For future I'll make sure to also include code for this kind of lessons as well when its not a project or exercise.
      Should be something like this:
      {
      "require": {
      "ramsey/uuid": "^4.2"
      },
      "autoload": {
      "psr-4": {
      "App\\": "app/"
      }
      }
      }
      assuming that you are following the same folder/namespace structure. Add that in & run composer dump-autoload again

    • @johongirrahimov2343
      @johongirrahimov2343 3 роки тому +1

      @@ProgramWithGio Oh man, I can not thank you enough. You don't know how happy I feel now, I spent hours to fix this issue. Pro is pro. you are my PHP hero. thank you a lot again and god bless you to have 1+million subscribers sooner

  • @saldinhozey4967
    @saldinhozey4967 Рік тому

    Hi Gio, Nice tutorial, I am trying out this illustration but nothing is being printed out as output. Please help.

    • @ProgramWithGio
      @ProgramWithGio  Рік тому

      Hey, thank you. Can you share your code? You can DM me on Twitter & send me screenshots or link to GitHub repo and I can take a look.

  • @mahmoudadel8313
    @mahmoudadel8313 2 роки тому +1

    why u didn't talk about traits bec it's related to inheritance topic

    • @ProgramWithGio
      @ProgramWithGio  2 роки тому

      Traits has a dedicated lesson & it's not directly related to inheritance

    • @mahmoudadel8313
      @mahmoudadel8313 2 роки тому

      @@ProgramWithGio when I Google it about traits I found it's present in php to make php support multi inheritance is it ?

    • @ProgramWithGio
      @ProgramWithGio  2 роки тому +1

      @@mahmoudadel8313 in a way yes, since PHP has no native multi inheritance support, traits can be used to kind of achieve that but it's not really multiple inheritance. Check the playlist there is a lesson about Traits.

    • @mahmoudadel8313
      @mahmoudadel8313 2 роки тому

      @@ProgramWithGio ok I will continue this great playlist by the way u are amazing thank u

    • @ProgramWithGio
      @ProgramWithGio  2 роки тому +1

      @@mahmoudadel8313 👍. Thank you 🙌

  • @deepakpatil4196
    @deepakpatil4196 Рік тому

    oh my toaster🤕

  • @MahmoudAhmed-pc2xw
    @MahmoudAhmed-pc2xw 10 місяців тому

    Best PHP and complete course. Better than many paid bootcamps and best quality