What Is Late Static Binding & How It Works In PHP - Full PHP 8 Tutorial

Поділитися
Вставка
  • Опубліковано 18 вер 2024
  • In this video, you'll learn what early & late binding are as well as what late static binding is. By the end of this video, you will also know the problem with statics when it comes to inheritance & how late static binding solves that problem.
    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.13
    Course Outline - github.com/gge...
    Course Playlist - • Learn PHP The Right Wa...
    RESOURCES
    Lesson About Static Properties & Constants - • Static Properties & Me...
    Resources - www.php.net/ma...

КОМЕНТАРІ • 97

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

    best php course, better than paid bootcamps

  • @mwaas
    @mwaas Рік тому +17

    Best explanation ever
    I hope you reach a million subscribers one day because you provide fabulous content

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

    I watched so many tutorials about different technologies but this sounds as the highest level of knowledge, skill set and the way of explanation and expression. Really damn great job!!!!!
    BTW: I had a discussion with my team leader. He always likes to be right. I claimed and still claim that in late static binding the 'static' keyword is used in the parent class and 'self' in the child class. He claims that 'static' must be present in both classes and that 'self' must not be used in either class. That makes no sense to me. I would like to hear your opinion (although everything can be seen from this video).

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

      Thank you so much 💙💙.
      To answer your question, there is no strict rule that "static" has to be used in parent or child. It should be used where late static binding is needed. Same goes for self, it can be used whenever you don't need late static binding, if you don't use inheritance then using self is fine. Your team lead may have a specific reason on why he enforces usage of static, have you asked him?

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

      @@ProgramWithGio thank you so much. I'll check that and let you know.

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

      @@donmikele07 no problem 👍

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

      I agree

  • @benderbg
    @benderbg Місяць тому

    This lecture was intense but that is how we like it. Thanks Gio!

    • @ProgramWithGio
      @ProgramWithGio  24 дні тому

      Yup, moving onto more challenging topics. You got this 💪

  • @2008rol
    @2008rol 2 роки тому +4

    Wonderful tutorial.Finally I understand the difference between self and static. Keep going and I really enjoy all of your tutorial

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

    I still don't understand that thumbs down on this video. Thank you Gio for this great content. Am a big fan of your chanell and share your contents with friends and PHP groups. Continue being awesome as usual and know that you are appreciated. Don't be discouraged and dispirited am 100% sure this channel will be a big hit for PHP ninjas. Do a detailed laravel beginner 101 course like this one, unearthing the basics that other courses skip. Do same on core basics on javascript too and how it works and put it on udemy for full course and snapshots on youtube for marketing. Will buy and definitely anyone on udemy. Definitely deserved. Continue being awesome man.One❤

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

      Thank you so much Hakeam 🙏. I certainly don't get discouraged cause of few dislikes, don't worry 🙂. I understand that someone may not like or agree with my content and that is perfectly fine. Also there are ton of bots that auto dislike stuff so not a big deal. If someone has an issue I would hope they would post a comment raising concerns and I would be happy to clarify or answer. I'm planning on more Laravel content soon 👍

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

      wow, ppl have different opinions and thoughts, welcome to the real life. Get used to it.

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

    Wow!!! What an amazing explanation!!!

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

    Thank you, that's a very useful course

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

    Man, I'm used to read the documentation but you make it so much easier and faster to pick up on everything, I'd triple like every vid if I could, alas ony have 2 accounts lol

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

      I'm super happy to hear that, thank you 🙏

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

    Your tutorials are strictly for the elites that will become good php programmers😌..........you teach us what youtubers don't talk about

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

      It's for all kinds of levels. I try to teach the way I would want to learn. These are the type of stuff you will encounter at work so I want to make sure I cover it with enough detail

  • @adrianez-programuj3313
    @adrianez-programuj3313 3 роки тому +4

    Nice Job!

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

    This is perfect! 😃really well explained, thanks

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

    Sir please make a video on php attributes introduced in php 8

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

      Yup, PHP8 attributes feature will be covered in this course, a bit later though

  • @Mahmudulhasan-ts5hm
    @Mahmudulhasan-ts5hm 3 роки тому +2

    Thanks

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

    Keep going, don't give up!

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

    This concept is quite hard to grasp but you explained it very well. Thanks!

  • @TricoliciSerghei
    @TricoliciSerghei Місяць тому

    Very nice explanation, thank you very much!!

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

    Very well explained 👍

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

    thank you so much!! the work you have done is amazing!

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

    Another great tutorial. Thank you for sharing all these concepts

  • @coder236
    @coder236 10 місяців тому

    incredible tutorial on this, thanks for taking the time to make these videos

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

    Only if I had an instructor like you back in my university days

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

    Goddamn, man. Hard topic, and you've dealt with it perfectly. Thank you!

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

    I understand quite well even though I long to understand in practice too. Let me keep forging ahead. Thanks Gio

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

      That's awesome, like following your journey

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

      nice of you to say that Gio. It's tough though...

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

    ***SUMMARY***
    So self inside Class always refers to that Class self is used in
    static inside method refers to Class that called that method static is in

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

    Nice explanation. :)

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

    Nice! It's popular interview question :D

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

      Yup 🙂

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

      @@ProgramWithGio It would be great if each episode could have gist or repo code to see :)

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

      @@alexios4392 some later episodes have link to repo

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

    Hi Gio , what do we intend exactly with "resolving a class" or "class resolution"?Also , for non native speaker like me , what is binding in general in php exactly?

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

      Hello, resolving basically means loading the class & all of its dependencies. Binding can mean different things in different contexts. For example in terms of variable bindings they get associated with some sort of identifier internally that reference the object, you can think of it as scoping as well if that helps.

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

      @@ProgramWithGio thanks, Gio! But honestly... I still don't understand it at all. I mean, the effects of using the "static" keyword in your video are clear because you illustrate it with multiple examples. However, I still don't get the terms used throughout the video. As pointed out, binding can mean various things in different contexts but what about this particular context? In other words, what gets bound to what in your specific code? If it's a topic too vast to cover in a single comment, could you please recommend some beginner-friendly resource that can clear things up?

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

      @@ryanford516 no problem. Don't overthink the term "binding", think of it as variable being bound to its value like object. It can happen at different times. Not sure what resource I can suggest about it, you can try googling more about late static binding.

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

    well explained!

  • @ilya_123__
    @ilya_123__ 10 місяців тому

    thank you!

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

    Thank you.

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

    Hey Gio, thanks a lot for your great content, a really appreciate your efforts on providing us this high quality knowledge!
    One thing that i find a bit hard to understand and that there isn't much of information out there , is the idea of forwarding-call and non-forwarding call, could you please give us some thoughts on this?!

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

      Hello, thank you 🙏. I talked about it a little bit at around 6:12. Also the 2d paragraph in PHP docs explains it as well: www.php.net/manual/en/language.oop5.late-static-bindings.php

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

    This was a great explanation. However, I'm in a strange situation where `new static` is used in a class static method that apparently has no child or parent classes 😆 so I don't understand why it's there.

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

      Not sure what you mean? Class B extends Class A. Maybe you missed it in the video.

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

    Thanks a lot 👏

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

    Hey Gio, thank's for this great content!
    At 9:39, why are your returning static() and not static (without parentheses), it works the same in my IDE in both cases!
    Thank's for all you're doing, it's awesome!

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

      Hello, thank you. No particular reason, just a habit & preference. I do same with regular class instantiations like new Invoice() vs new Invoice when no arguments are needed for the constructor. To me it makes sense to have parenthesis because it invokes a method in this case a constructor which is still a method call and method calls have parenthesis

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

      @@ProgramWithGio Thank's!

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

    Hey Gio, I want to thank you for this awesome PHP Tutorial I'm learning alot. I'm going to learn Laravel after using Laracast. Do you think I'll need to watch the whole 110 videos to jump into laracast ? If not, can you tell me the video number where I should be ready ?
    Thanks again!

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

      Hey. You're welcome, happy to hear that you are learning alot. It depends on your level and if you feel comfortable starting Laravel. You can start it and if things seem hard or complicated then come back and continue watching the videos here. I personally would at least finish 3rd section because we cover some important topics there. Up to you though 👍

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

    Good tutorial. I don't understand some points, could you explain them to me?
    The difference between static and $this variable in a non-static context is that: if you call the method using the $this variable, it could call a private method from the same scope while using static could result in a different method call.

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

      Thanks. If you had a private method in the same class & you used $this it would call that method from the same class, however with static:: it may call the parent one depending on where its called from

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

      Thanks for your explanation@@ProgramWithGiobut it's still unclear to me. Let me give an example:
      class ClassA1
      {
      public function showClassName()
      {
      echo $this->getClassName();
      }
      private function getClassName()
      {
      return 'A1';
      }
      }
      $classA1 = new \App\ClassA1();
      $classA1->showClassName();
      We have a private method: getClassName, we use $this in the method showClassName to call the private method getClassName.
      After we run the script we get the result "A1"
      If I have ClassB1 extends ClassA1
      class ClassB1 extends ClassA1
      {
      }
      How can I implement what you have stated with $this and static::?

  • @user-mo3cw6go7c
    @user-mo3cw6go7c Рік тому

    There are many claims that PHP is a dead language, from video to video I see how it has risen to life again!

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

      Heh, thank you 🙌. PHP isn't going anywhere regardless of what many might believe.

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

    3rd UA-cam video on Late Static Binding today. No need to go on to a 4th

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

    👍👍👍👍👍👍👍👍👍

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

    7:43 i didn't understand this, is there any example or article that can help understand this

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

      PHP documentation is a good source: www.php.net/manual/en/language.oop5.late-static-bindings.php

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

    Can i use self for non static method calls?

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

      You could but I'd suggest to use $this instead

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

      @@ProgramWithGio but if i want to ensure that method implementation from the current class is used and not from any child class?

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

      @@aleksandrkanygin2672 use this

  • @yizain1891
    @yizain1891 10 місяців тому

    If none-static name set to private, classB->getName() echos A, but protected works correctly, this is strange