PHP 8.4: Lazy Objects Explained (So Cool!)

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

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

  • @peterfox-dev
    @peterfox-dev 14 дней назад +9

    This will be great for API clients, you can now provide objects that don't call the API until the object is accessed. Might even work for a Model's relationship as well. E.g. 1 to many, provide a collection with a lazy load to run a specific query only once the collection is interacted with.

  • @jonathanhavens7183
    @jonathanhavens7183 13 дней назад +3

    This makes sense now as to why the community wasnt as excited at it seemed they should've been.
    If Nuno is just realizing this, that means the majority of others haven't come around yet either. The bootstrapping process/containers can now be lazy all the way down (like you quickly touched on). For dynamic languages, this is genius.
    I cant wait to see the performance gains and drops in resource utilization once this feature/RFC is fully realized across the community. Used with property hooks, a whole new paradigm just opened up to us, really.
    Thank for putting this out there Nuno 👌, great to see!

    • @mnapoli_
      @mnapoli_ 12 дней назад

      I wouldn't expect crazy gains for end users I think. Frameworks already use lazy objects today, but implemented in PHP code (tbh I don't know if Laravel does, I always assumed it did). The fact that PHP supports it natively in 8.4 means frameworks/libraries can now get rid of their custom implementations. This might be a tiny bit faster though (because PHP's native version might be a bit more efficient).

    • @jonathanhavens7183
      @jonathanhavens7183 11 дней назад

      @@mnapoli_ I know Nikolas Grekas mentioned hitting a threshold while maintaining the vanilla PHP library on this, which I know will help in the Symfony/Laminas worlds. But you're right, it will only be small gains in their neck of the woods. As for Laravel, there are deferred service providers for most of the non-essential services. That's really the closest they have to date. We shall see, good point though.

  • @HaraldEngels
    @HaraldEngels 11 дней назад +2

    PHP 8.4 doesn't appear shiny at the first glance but my gut feeling is telling me that this version is a huge step forward by being able to do such things. It indicates that a lot of important work was done "under the hood" to modernize the PHP core. Lazy objects will solve some performance problems for me which were bothering me for 16 years.

  • @ciberman
    @ciberman 8 дней назад

    This would be amazing for DI. One little question would be what is the performance penalization in property accesses. I know for most cases would be orders of magnitude less compared with the object constructor, but I am still interested.

  • @mariobatista30
    @mariobatista30 14 дней назад +5

    This would be very interesting in Laravel in case of the dependency injection when the constructor receives all dependencies but the object is created when the properties/methods are just accessed. 🤔

  • @vitaliisheverov
    @vitaliisheverov 13 дней назад

    Really cool feature for framework developers. Laravel and Symfony DI might need to rethink their code, and Doctrine already has lazy relationships-so it’ll be interesting to see if Eloquent finds a way to use this new feature!

  • @JeankMelendez
    @JeankMelendez 8 дней назад

    What is your IDE name? Nice video, thanks

  • @LaravelJutsu
    @LaravelJutsu 14 дней назад +2

    dope.