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

Поделиться
HTML-код
  • Опубликовано: 28 ноя 2024

Комментарии • 104

  • @federicobau8651
    @federicobau8651 2 года назад +7

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

  • @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!

  • @ינוןאלבז-כ1ז
    @ינוןאלבז-כ1ז 2 года назад +4

    This channel is the channel with the most value on RUclips, 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 2 года назад +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.

    • @ProgramWithGio
      @ProgramWithGio  3 года назад

      That's awesome :). Thank you so much 🙏

  • @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 🙏

  • @tolebiGamingTime
    @tolebiGamingTime 2 месяца назад +1

    Good lesson

  • @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 🏆

  • @Vitalii-m6r
    @Vitalii-m6r Год назад

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

  • @tomekmacccc11
    @tomekmacccc11 Год назад

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

  • @faramarztayyari3734
    @faramarztayyari3734 3 года назад +1

    Thank you for this awesome 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

  • @Armando-px8hi
    @Armando-px8hi Год назад

    The best of the best!)

  • @baptistedara8026
    @baptistedara8026 2 года назад

    you are amazing dude
    thank you

  • @josephnduati1214
    @josephnduati1214 Год назад

    Thanks a Ton!

  • @abduabdu7404
    @abduabdu7404 Месяц назад

    Hello Gio, in the examples of using the call() method why didn't you use the splat operator and instead used call_user_func_array(), is there any advanced reason for that, like a better performance from call_user_func_array()?

    • @ProgramWithGio
      @ProgramWithGio  Месяц назад

      Probably an old habit. Yes the splat operator would work as well & is actually probably faster than using the call_user_func_array

    • @abduabdu7404
      @abduabdu7404 Месяц назад

      @@ProgramWithGio Thank you for your response, its not only the course that is great but also you as a person for not being arrogant and helping others learn what is best to learn and updating the course two years later❤

  • @МаксимСлободянюк-н9о

    Thank you SO MUCH!!!

  • @ilya_123__
    @ilya_123__ Год назад

    thank you!

  • @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

  • @memack101
    @memack101 2 года назад

    Thank you.

  • @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 RUclips and slow it down for those that are too fast

  • @lxbdr
    @lxbdr 2 года назад

    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  2 года назад

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

  • @Em1lka_
    @Em1lka_ Год назад

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

    • @ProgramWithGio
      @ProgramWithGio  Год назад

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

  • @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.

  • @keremardicli4013
    @keremardicli4013 Год назад

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

  • @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.

  • @DAG_r8
    @DAG_r8 2 года назад

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

    • @ProgramWithGio
      @ProgramWithGio  2 года назад +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.

  • @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 🙌

  • @SaiyanJin85
    @SaiyanJin85 Год назад

    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  Год назад

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

    • @SaiyanJin85
      @SaiyanJin85 Год назад

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

  • @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.

  • @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

  • @bakre_dev8728
    @bakre_dev8728 Год назад

    Thanx 🎉

  • @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.

  • @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.

  • @chenting71
    @chenting71 2 года назад

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

  • @أحمدكلش-ض3ع
    @أحمدكلش-ض3ع 2 года назад

    i hop you start laravel course before i finish this course

  • @hancysp
    @hancysp 2 года назад

    volim

  • @sergeisurin2963
    @sergeisurin2963 Год назад

    👍🙏

  • @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 2 месяца назад

    Hey, Gio, thanks for your hard work, I love course very much so far!
    Just wanted to add that code on ruclips.net/video/nCxnzj83poQ/видео.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 2 месяца назад

      I just watched video further, so nevermind 😀

    • @ProgramWithGio
      @ProgramWithGio  2 месяца назад

      Hey, thank you. Yea the error would make sense if you comment out that part :)