PHP Enums With Practical Examples - Full PHP 8 Tutorial

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

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

  • @BrenIrwin
    @BrenIrwin 2 года назад +10

    Thank you for putting this together. I've looked online specifically for practical PHP examples and struggled to find anything of use. This video, like all of yours, is very helpful.

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

      You're very welcome! Glad it was helpful.

  • @Zubbee
    @Zubbee 2 года назад +2

    I got caught up with practicing this lesson. I made up my own invoice data and added some classes, some code and uploaded the values in a new table in the database so as to work together with the exercise you gave at the end of section 2. It was a great experience. I'm amazed at how much this course has thought me. Thanks Gio. The Enums feature seems really cool. I'm pleased to be learning PHP8. It makes me think that the much older versions may have been tougher to work with. lol. Thanks again Gio.

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

      For sure, PHP is getting better & better with each new version

  • @DanFletcher90
    @DanFletcher90 2 года назад +6

    Love seeiythe quality of your videos just keep going up and up!

  • @akeemakeem3862
    @akeemakeem3862 Год назад +1

    I really love your video's i have really struggled with the exact use case for enum but you just made it very simple

  • @yuriymiroshnychenko5446
    @yuriymiroshnychenko5446 2 года назад +1

    Great and very helpful video as always! Thanks!

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

    I wish I have started php with this tutorial... really profound with great examples and explanations

  • @sharifurrobin7720
    @sharifurrobin7720 2 года назад +2

    love your explanation always 😍

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

    Before we had 'Enums', I would use an interface as you can have defined 'const' in them. It made them readable and easy to find in code. Obviously, 'Enums' are a more complete solution. Thanks for explaining. Appreciated.

    • @ProgramWithGio
      @ProgramWithGio  10 месяцев назад +1

      Yup, enums are definitely a step up

  • @mirodil.kamilov
    @mirodil.kamilov 2 года назад

    Really insightful. Thank you a lot. I can't even imagine how much effort you put in

    • @ProgramWithGio
      @ProgramWithGio  2 года назад +2

      Thank you, yes a lot of effort & love goes into each video but it's worth it & I enjoy making them.

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

    Huge amount of information, thanks for everything ❤

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

    Excellent video.

  • @thexp777
    @thexp777 Год назад +1

    At this point I just like the videos before even watching them.

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

    Great video thanks

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

    Thank you very much for explaining it so nicely and creativley

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

    THANK YOU!!!!!!!

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

    This is very good teaching

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

    Thank you)

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

    Thanks for the amazing topic 👍. Keep it coming.

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

    Super high quality content as always

  • @omaryahia
    @omaryahia 8 месяцев назад

    wow amazing🌟

  • @mmk-69420
    @mmk-69420 2 года назад +1

    Thank you for this amazing course!
    I've some questions tho. How advanced are we if made it to this video of the course? When do you think this course will be over?
    I definitely would've paid to get a complete course from you, your explainations are simple and concise. Again thanks !

    • @ProgramWithGio
      @ProgramWithGio  2 года назад +2

      There are more topics I want to cover before we end the series & there is also a project towards the end. Getting through this course is good & will give you the good foundation but you need to practice & apply the knowledge by working on projects, otherwise it will fade away. That's why we'll work on a project towards the end

  • @Lyrik-Klinge
    @Lyrik-Klinge 2 года назад

    You made a good job, THANKS!

  • @aleksandrkanygin2672
    @aleksandrkanygin2672 2 года назад +1

    Thanks for another great lesson, at 14:28 after creating an enum case object using tryFrom, can't we just acccess the name property and display it?

    • @ProgramWithGio
      @ProgramWithGio  2 года назад +2

      Yes but name will not always be something user friendly

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

    Awesome!

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

    Amazing video as always
    BTW can you make a course about Aynchronous php and ReactPHP
    Would be great

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

      Thank you. That is something I want to explore and learn myself first, so perhaps in future.

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

    Thank you your tuto are amazing :) :)

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

      You're welcome, thank you for support 💙

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

    How you organize enums? We use database table for something similar, because there are more then 1000 “constants” in unique groups > group = enum.
    I don’t think would be wise to create 200 files with enums.

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

      It depends on the structure for sure, if you have that many enums then maybe a different strategy is better like storing in database. For example, you wouldnt store country codes as constants but instead store them in database

  • @andreaseisermann1045
    @andreaseisermann1045 9 месяцев назад

    Hello, I need help,
    I'm working with an Enum: Error_Code: int and trying to create an error output with another Enum_Code_De: string. I'm sure it should work, I just can't figure out how.
    Maybe as a topic for another tutorial

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

      I dont really understand the issue. I need more information & possibly actual code to be able to answer.

  • @AliHassan-wc6nb
    @AliHassan-wc6nb 2 года назад

    Sir, how to run Async functions and background jobs. You are doing a great job. It's great to have all required things together in a correct way. How to usewhen to use what!! Please try to cover reportinv in php also!

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

      Thank you. We will cover background jobs like cronjobs soon in this series. What do you mean by reporting? Like reporting logs?

    • @AliHassan-wc6nb
      @AliHassan-wc6nb 2 года назад

      @@ProgramWithGio feels great to get a reply! I am more concern about the async calls, when UI gets stuck I need to implement something like async calls within Php.
      I never worked on reporting part in php. Is there open source tool for database reporting like BI reports

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

      @@AliHassan-wc6nb you could make ajax calls, depending on what you are using for your frontend. Axios is a good library for async js calls.

    • @AliHassan-wc6nb
      @AliHassan-wc6nb 2 года назад +1

      @@ProgramWithGio thanks for the suggestion, will check this. Thanks you, thank you so much.

    • @AliHassan-wc6nb
      @AliHassan-wc6nb 2 года назад

      @@ProgramWithGioany suggestion for implementing multi threading in php? 🤣😜🙏🏻

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

    Gio, the Github contains the finished code for the end of the video. It is a bit difficult to copy/paste the code when I am in the middle of the video. I am all excited with the course but this is slowing down my progress.

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

      Yes the code in branches are complete codes for the lesson. The project that we work on at the end has 2 branches for each lesson the start & the end so that way you can choose which one you want to use.
      The source in the repo for these lessons are not meant to be copy/pasted, its there to see/reference the final code for the lesson. You should write the code as you are watching the video. The code is usually the same as previous lessons, so just continue from where you left off before and if a file is missing then you can check the final code for the lesson and add it in.
      I know its not the most efficient way but that's the best I could do for that time. With the project its a bit easier given that it has 2 branches per lesson.

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

      @@ProgramWithGio I understand. Just highlighting my predicament. Sorry for that.

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

      No worries, sorry that it's creating blockers for you. It gets better in project section

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

    At timestamp 24:32, VS code highlights the self::Paid and others as "Undefined Class Constant". Though the app works fine though not sure why the errors?

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

      Yea that's fine because the constants are not defined in trait they are defined in a class that uses that trait. VSCode is not a full IDE so it cant trace it back properly which is why it highlights it. PHPStorm is able to trace it and thats why it does not underline it.

    • @truthteachers
      @truthteachers Год назад +1

      @@ProgramWithGio Fantastic, I have also referred this problem to the developers of the Php Intelephense extension which i have a paid license. Lets see what we get back.

    • @davidmutua6971
      @davidmutua6971 4 месяца назад

      @@truthteachers Intelephense extension fixed it already

    • @truthteachers
      @truthteachers 4 месяца назад

      @@davidmutua6971 i am no longer using intelephense. I am using PHP Tools by Devsense

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

    Gio, i am puzzled with the new problem is am facing at timestamp 26:39. When i enter url as "localhost:8000/invoices" everything works fine but when i enter the url as "localhost:8000/invoices/" it goes into error page. Is there a reason for this?

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

      By default, Nginx treats URLs with and without trailing slashes as separate locations. You would need to modify the nginx config to handle trailing slashes if you need that

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

      @@ProgramWithGio I am using the PHP built-in server and same happens. Alternative, I resolved it coding 2 Get attributes in InvoiceController to cater for both scenarios and it works fine. Thank you so much.

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

      @@truthteachers yup that's an option as well 👍

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

    Is there any use case of pure enum ?? I think enum without value is pretty useless.

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

      Yes when you don't need to save the value in database for example, something internal.

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

    👍

  • @rahulchavan.
    @rahulchavan. Год назад

    is it possible to load an enum based of its name? since enum can not be instantiated , $enum = new 'enum class name not possible'

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

      You can do Enum::tryFrom(value) or Enum::from(value) for backed enums

    • @rahulchavan.
      @rahulchavan. Год назад

      thank you for the response, you did not get my point, i am trying to load enum dynamically, i have a string name of enum class ,but can not call tryfrom on string..

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

      @@rahulchavan. yes you can if your enum is backed enum and is type string. Maybe I'm not understanding the question properly. Maybe if you share an example code I could better understand

    • @rahulchavan.
      @rahulchavan. Год назад

      say for example , i have ten's of enum class ,and i have fqcn of each class, i would like to load enum dynamically, if i know which enum to load i would do enum::tryfrom, but i can not do (fqcn)::tryfrom because fcqn is just a string.sorry if this is confusing or not able to make you understand.

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

      @@rahulchavan. I think I understand, you should be able to do it by storing the enum class name in a variable & call methods on it like $enum = 'YourEnum'; and then $enum::tryfrom() that should work, have you tried it? Do you get any errors?

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

    Personally i would never do color inside my backend code. Color is purely a frontend representation of data.

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

      Totally agree, though in some cases it comes in handy. Just an example of enum

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

    it is really eye opening and all but you're too fast. breath a little man

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

      You can slow it down on RUclips 👍

  • @user-zh2oz9fe4m
    @user-zh2oz9fe4m Год назад

    Enums are pretty useful. I found an interesting composer package that makes Enum cases invokable - archtechx/enums