#[Override] attribute is coming to PHP 8.3

Поделиться
HTML-код
  • Опубликовано: 13 сен 2024
  • This is the "#[Override] attribute" segment from my "What's new in PHP 8.3 " livestream. Watch the full livestream here: www.youtube.co....
    ----------------------------------------------------------------------------------------------------
    - Twitter: / enunomaduro
    - Telegram Group: t.me/+RoAqqaaS...
    - Threads: www.threads.ne...
    - Mastodon: mastodon.socia...
    - LinkedIn: / nunomaduro
    - RUclips: / nunomaduro
    - GitHub: github.com/nun...
    - Bluesky: bsky.app/profi...
    - Tiktok: / enunomaduro

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

  • @ricardodelacrvz1400
    @ricardodelacrvz1400 11 месяцев назад +3

    estou a usar a tua library openAI PHP e vim aqui dar follow. é bom ver portugal a representar.

  • @spicynoodle7419
    @spicynoodle7419 11 месяцев назад +4

    Very cool, although we should strive towards not using inheritance

  • @hrsa
    @hrsa 11 месяцев назад +3

    This may be a stupid question, so beware :)
    In your code, the returned value is 'foo', from the parent class method - even when the override attribute is used. Basically the foo() from the child class isn't used at all, just to check if the method exists in its parent.
    So why go to all those lengths with an #Override attribute? Just to ensure the method exists in the parent class?

    • @GabrielPHahn
      @GabrielPHahn 11 месяцев назад +1

      The var_dump method is been used in a Person class, not an AnotherPerson class.
      That's why it shows foo when he runned in terminal.

    • @hrsa
      @hrsa 11 месяцев назад +1

      @@GabrielPHahn oh yes, you're right... Thanks! It makes sense now 🙂

  • @moofymoo
    @moofymoo 3 месяца назад

    imho keyword would be better, just like PHP already have readonly, that does the same as readonly in C#

  • @foodallergyguides2721
    @foodallergyguides2721 11 месяцев назад +2

    Thanks for the amazing tutorials. Can you make a video about sublime setup for php? thanks

    • @nunomaduro
      @nunomaduro  11 месяцев назад

      Great suggestion!

  • @MrYevelnad
    @MrYevelnad 10 месяцев назад

    Poeple are moving on with Composition and PHP is still making icing for Inheritance.

  • @hetparekh21
    @hetparekh21 11 месяцев назад +2

    This may be a noobie syndrome but I don't get it 🤷
    Like why would someone need this ?
    Explanations are welcomed 🤗

    • @nunomaduro
      @nunomaduro  11 месяцев назад +3

      Well, this attribute is used to indicate that a method in a subclass is intended to override a method in its parent class. It helps to ensure that you are actually overriding a method as you intend, and it provides better code readability.
      RFC: wiki.php.net/rfc/marking_overriden_methods.

    • @spicynoodle7419
      @spicynoodle7419 11 месяцев назад +4

      PHP is slowly moving to a more strict and type safe version of itself.
      In the example, the parent class provides something like an interface that child classes can either inherit or override. You may decide to rework the interface and remove the method from all classes. However, it's easy to miss a child class that has the method and have it malfunction silently. This annotation makes the intent of the programmer much more clear and provides a way for LSPs like IntelliPhense, PHPactor, PHPstan and so on to perform static analysis and give you squiggle lines in the editor or warnings during CI.

  • @rizkyanfasafarrasmada7225
    @rizkyanfasafarrasmada7225 11 месяцев назад +1

    Similar like java 😮

  • @hasanablak
    @hasanablak 11 месяцев назад +2