What Are PHP Magic Methods & How They Work - Full PHP 8 Tutorial

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

КОМЕНТАРІ • 98

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

    A real road map to learn PHP. Sometimes, I have to spend good time offline to grasp and have chewed understanding of your tutorial. Which is expected. Greatgreat guidance!

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

    Best php magic method tutorial and best php course, better than paid bootcamps

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

    This channel is the channel with the most value on UA-cam, and on the web in general, by far

  • @bewildstudio
    @bewildstudio Рік тому +6

    Super professional video tuts... so many details...even mid devs find a lot of interesting things. What a job has been done! Thank you! Definetly donate, if i find a job)

  • @non9831
    @non9831 Рік тому +9

    This is how to make php great again, very good content

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

    7 pages of notes on this video (with code examples) :D You are on another level with you knowledge and ability to clarify compared to all of the other sources.

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

    Sir also include exception handling in this oop tutorial. Your tutorials make doubts crystal clear

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

      Definitely, exceptions lesson coming up soon

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

    man your vidoes make everything clear thank you so much for this great content.

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

      Glad to hear that, you're welcome & thank you 🙏

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

    Gamarjoba, Gio! Great tutorial! Thank you for your hard work! TM from PL :-)

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

    Man you keep on rockin! Starting at 00:00 I must admit that I thought that this video is going to be of no interest to me.
    I was wrong.
    __invoke & __toString are most interesting to me. Where __call & __callStatic are not short after.
    Wonderful, thank you Gio 🏆

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

    Thank you for this awesome tutorial

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

    There are plenty of magic methods. Thanks for this tutorial!

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

    Watched thrice already. Each time things were clearer but I still didn't get some magic methods (__call and __callStatic). But you did say not to worry if we don't get it as of now. Thanks alot Gio

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

      You'll see more examples of call & call static in third section and will understand it more 👍

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

    Another great tutorial. Thank you for sharing all these concepts

  • @CarlosOrtiz-sz2pp
    @CarlosOrtiz-sz2pp 2 роки тому

    Magic methods are very interesting lesson. thank you

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

    Thanks a Ton!

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

    The best of the best!)

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

    thank you!

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

    Thank you.

  • @user-bf5sb1fs1w
    @user-bf5sb1fs1w 2 роки тому

    Thank you SO MUCH!!!

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

    you are amazing dude
    thank you

  • @vkmishra.singer
    @vkmishra.singer 2 роки тому

    Great!! I request you to please create the course for laravel and explain whatever OOPS concept is used there.

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

      Thank you. I'll have more laravel content once I finish this series

    • @vkmishra.singer
      @vkmishra.singer 2 роки тому +1

      @@ProgramWithGio Thanks. I will be waiting for new awesome laravel series.

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

    Thanks for your great tutorial. I request to you that can you please make your playback little slow.? sometimes I really get over whelmed by your speaking speed.

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

      Thanks for the feedback. I know about that and improved on it in later videos. You can also adjust the speed on UA-cam and slow it down for those that are too fast

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

    Thanx 🎉

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

    Thanks for the great video!
    I think using the magic methods should be done when someone builds a framework or something like that. I see no reason to use the_get or _set_ for example on a project that has business logic, imagine unsetting or setting properties on the fly...

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

      It depends, it can be useful in non framework/library code as well. Although, I agree with having less magic in userland

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

      @@ProgramWithGio Thanks for the reply and your videos! Great job!

  • @AbdouAbdou-hu9un
    @AbdouAbdou-hu9un Рік тому

    thank you @Gio,
    in 14:51 you said you needed class with one method than why didn't you just declare a function instead ?

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

      You could, it's just if you have a class with just a single method you might like the invokable option better, it comes down to preference, nothing wrong with having a single method in a class

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

    Magic methods are indeed magic. It is hard to wrap my head around.

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

    Amazing series thank you. After years with php still something to learn. Can you deep dive to laravel to show those magic methods in action?

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

      Thank you 🙌. I'll be doing more Laravel content in 2023

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

      @@ProgramWithGio Glad to here that. Wish you best of luck

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

      @@kvanca2330 thank you 🙌

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

    Thanks for the great series! Do I get it right that the __invoke pattern can be used to make a function available to a class via DI so it is a explicit dependency instead of relying on a regular function to be present?

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

      Invoke just makes class be called as a function. Makes something like this possible: (new A())()

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

    Hey Gio ,what's the difference between accessing properties as $this->$property and as $this->property , cuz both ways work!

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

      $this->property accesses the value of the property defined in the class, $this->$property access the value of a property whose name comes from the value of variable $property. Its variable variables, we covered that in first section.

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

    Sir really i have watching this video 10 time ...i cant remember this lots of information...how can we practice to get a better more understanding practicaly

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

      The best thing to do is try it out on a project. Build a todo list or even refactor the exercise from the first section and try to apply magic methods to it.

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

    Hi Gio, could you recommend any plugins for php storm? Something for php/laravel

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

      I don't really use any plugins, only when I have specific needs but for the most part phpstorm is enough

  • @أحمدكلش-ض3ع
    @أحمدكلش-ض3ع Рік тому

    i hop you start laravel course before i finish this course

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

    By the way, I understand those magic methods as "Event Trigger" provided by PHP, when operating on $object :D

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

    Hi Gio, thank you for this , What is the advantage of using __invoke vs calling a function from the constructor ?

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

      It's ideal if you don't execute any methods in constructor because then when you inject that class as a dependency anywhere else if you use autowiring DI it will be executing it every time and can affect performance depending on what the method is or worse perform some updates again depending on what that method does.

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

    Is there any reason why one would do a single responsibility class with the __invoke magic method, when one could just maybe write a simple function? 🤔

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

      Mostly it's preference. Usually used got single action controllers or when you have action classes with single methods. You can also pass an object of class as callable/closure when it is invokable, though I haven't tried this in awhile so you would have to test it

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

    Sorry, Gio, why do we have "return $this->$name"? I thought it should be the conventional "$this->name". Or have I missed something?

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

      It's called variable variables. We covered that in the first section. $this->name would return the value of name property where $this->$name returns the value of the property of whatever the $name evaluates to.

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

      @@ProgramWithGio
      Ah! Thanks. I didn't read it that way.

  • @AJ-Pixelyze
    @AJ-Pixelyze 3 роки тому

    Hey, I wonder if you could make a video of how to use PHP with javascript. I know how to use JS but when it comes to PHP and JS working together with HTML, I have no clue how to connect them when it comes to DOM to add some JS

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

      The project that we'll work on at the end of the series will have some JavaScript so that might be helpful.

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

    👍🙏

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

    volim

  • @FGj-xj7rd
    @FGj-xj7rd 2 роки тому

    There is nothing magical about these methods 👎

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

      That's what it's called 🙂

    • @FGj-xj7rd
      @FGj-xj7rd 2 роки тому

      @@ProgramWithGio I know 🤷🏻‍♂️

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

    public function __call(string $name, array $arguments)
    {
    if (method_exists($this, $name)){
    $this->$name(...$arguments);
    # instead of call_user_func_array([$this, $name], $arguments);
    }
    }
    Hi sir, I found out this, it also worked. Are they different ?

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

      That would work as well, in this example they are pretty much the same, might be some differences in terms of performance but I have not benchmarked it.

  • @aerohcss
    @aerohcss 3 дні тому

    Hey, Gio, thanks for your hard work, I love course very much so far!
    Just wanted to add that code on ua-cam.com/video/nCxnzj83poQ/v-deo.html will cause the error if you comment out the line $invoice->amount = 35;
    The Error is "Typed property app\Invoice::$data must not be accessed before initialization". I guess the solution is just setting to $data property default value []

    • @aerohcss
      @aerohcss 3 дні тому

      I just watched video further, so nevermind 😀