PHP Enums With Practical Examples - Full PHP 8 Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 29 ธ.ค. 2024

ความคิดเห็น • 107

  • @BrenIrwin
    @BrenIrwin 2 ปีที่แล้ว +12

    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 ปีที่แล้ว +3

    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!

  • @lairotuT-Tutorial
    @lairotuT-Tutorial หลายเดือนก่อน

    Fantastic topic and fantastic teaching! Thank you Gio!
    @23:14 You mention the first parameter of Router->register given as Enum object and change it to be string as the register method deserves it. I wonder why you change this at this spot? I instead passed through the Enum object here as well and change the register function to accept the HttpMethod object as I am able to get rid of the other hardcoded attributes inside get() and post() methods as well.

    • @ProgramWithGio
      @ProgramWithGio  หลายเดือนก่อน

      Yup you can do that as well, I just did not bother doing a lot of refactoring.

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

  • @akeemakeem3862
    @akeemakeem3862 2 ปีที่แล้ว +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!

  • @sharifurrobin7720
    @sharifurrobin7720 2 ปีที่แล้ว +2

    love your explanation always 😍

  • @delisandor5337
    @delisandor5337 2 ปีที่แล้ว

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

    • @ProgramWithGio
      @ProgramWithGio  2 ปีที่แล้ว

      Glad you like it, thank you 💙

  • @mustafabde
    @mustafabde ปีที่แล้ว

    Huge amount of information, thanks for everything ❤

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

  • @ryanqvincent144
    @ryanqvincent144 ปีที่แล้ว

    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  ปีที่แล้ว +1

      Yup, enums are definitely a step up

  • @memack101
    @memack101 2 ปีที่แล้ว

    Excellent video.

  • @aryank8695
    @aryank8695 2 ปีที่แล้ว

    Thank you very much for explaining it so nicely and creativley

  • @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 8 หลายเดือนก่อน

      @@truthteachers Intelephense extension fixed it already

    • @truthteachers
      @truthteachers 8 หลายเดือนก่อน

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

  • @cyeg12c
    @cyeg12c 2 ปีที่แล้ว

    Thanks for the amazing topic 👍. Keep it coming.

  • @restless_moon
    @restless_moon 2 ปีที่แล้ว

    This is very good teaching

  • @isaacsouza17
    @isaacsouza17 2 ปีที่แล้ว

    Super high quality content as always

  • @AMoktar
    @AMoktar ปีที่แล้ว

    Great video thanks

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

  • @omaryahia
    @omaryahia ปีที่แล้ว

    wow amazing🌟

  • @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 ปีที่แล้ว

    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  ปีที่แล้ว

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

  • @thexp777
    @thexp777 ปีที่แล้ว +1

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

  • @Lyrik-Klinge
    @Lyrik-Klinge 2 ปีที่แล้ว

    You made a good job, THANKS!

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

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

  • @invgreat5608
    @invgreat5608 ปีที่แล้ว

    THANK YOU!!!!!!!

  • @oseintow
    @oseintow 2 ปีที่แล้ว

    Awesome!

  • @sergeykonov4562
    @sergeykonov4562 ปีที่แล้ว

    Thank you)

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

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

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

  • @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? 🤣😜🙏🏻

  • @benderbg
    @benderbg 3 หลายเดือนก่อน

    This lesson was:
    • [E]xceptional
    • [N]ice
    • [U]nforgettable
    • [M]agnificent

  • @sergeisurin2963
    @sergeisurin2963 ปีที่แล้ว

    👍

  • @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 ปีที่แล้ว

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

    • @ProgramWithGio
      @ProgramWithGio  ปีที่แล้ว

      You can slow it down on TH-cam 👍

  • @Vitalii-m6r
    @Vitalii-m6r ปีที่แล้ว

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

    • @ProgramWithGio
      @ProgramWithGio  ปีที่แล้ว

      Indeed, they are. You're welcome 🙌