PHP Generators Explained - Full PHP 8 Tutorial

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

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

  • @purnimaaggarwal7656
    @purnimaaggarwal7656 ปีที่แล้ว +7

    I have many years of experience with PHP but was still always confused about Generator until I watched this video. Thank you

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

      Super happy to hear that, glad it was helpful 🙌

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

    I've watched dozens of these PHP series and are they definitely are the best out there! Very concise and comprehensive. Thanks! P.S. 20+ years in programming.

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

      Glad you like them, thank you 💙

  • @aleksandrkanygin2672
    @aleksandrkanygin2672 3 ปีที่แล้ว +16

    Your course is simply the best php course, thank you for your efforts

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

    Although not explicitly stated, what the 'generator' has to do is 'remember ' the complete current 'state' of the object it is 'part of' so that it can be 'restarted' by the 'next()' function. Obviously, this is the reason for the 'reduced' memory usage.
    It also allows for some 'interesting' coding techniques such as using 'co-routines' in a single PHP execution.
    'Generators' are a very powerful construct indeed. I was surprised to see them in PHP. I agree that most people will use them as shown here.
    Your explanations are very good. thank you. Appreciated.

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

      Good points, thank you 💙

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

      Boy you really like those quotes 😅

  • @Armando-px8hi
    @Armando-px8hi ปีที่แล้ว

    I do not know how but this video I just saw once and I understood every word that you have said, It is beacuse how you explaing. The greatest coach the PHP has ever seen!!!!

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

    This video actually does an excellent job explaining the keyword yield! Thank you!!

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

      Thank you, glad you liked it 🙌

  • @jackrourke9237
    @jackrourke9237 3 ปีที่แล้ว +7

    Thank you again for such a beautiful explanation for everything you teach ♥ ♥ ♥ ♥ ♥

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

    Let me iterate again 🤣👍 Great explanation of generator and very clear, very similar of Python and Javascript.

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

    for($i = 0 ; $i < 1000;$i++){yield "thank you for this lesson"}

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

    I know of and use yield semi regularly, but this is the first time i understood exaclty how it works. Pausing the execution is very counter intuitive in PHP, its almost like goto statements, so its difficult to wrap ones head around. Good stuff my man ❤

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

      Awesome, happy to hear 💙

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

    🥰 best tutorial and teacher i had seen The great Gio

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

    Great ❤ Just a kind note: Avoid retrieving all table rows at once even if you are using Generators because it fetches all the rows from the table which is not good if your table hold large amount of data . It's better to implement limit SQL clause to paginate data. He just demonstrate the the uses of generators but it's up to you to properly implement in your application.

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

    Succinctly explained. Thanks, man. Great work.

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

    This is impressive, I learned a lot in this video

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

    Again, another very valuable lesson that I would have to watch again. Thanks alot Gio.

  • @raerayan
    @raerayan ปีที่แล้ว +5

    As an idea, It would be awesome to hear something about DDD implementation with Laravel or design patterns that you commonly use. But it's already a great job! It's a great course. Thank you very much.

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

      Thank you for the suggestion 🙌

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

    Thank you for so easy explanation, your channel is the best )

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

    the best one as usual 🙌

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

    amazing, I guess first time I understand the yield statement finally !!🎉 thank you

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

    Nice Explanation Gio!!

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

    Thank you Gio for the great explaination and the efforts you put

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

    Love you! Perfect videos!

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

    Very helpful and well explained! Thank you!

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

    Amazing and great explained video! thx!

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

    Great stuff! Like over the top - best I've ever seen! Go on!

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

    Thanks, your tutorials are always well detailed

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

      You're welcome. Glad you like it 🙌

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

    Nice tutorial. I hope you also make one for PHP fiber

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

    Amazing explanation . Thanks a lot.

  • @processwire-rocks
    @processwire-rocks 2 ปีที่แล้ว +1

    Brilliant explanation, thank you very much!

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

      You're very welcome, thank you 💙

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

    Rermarkeble tutorial! Thanks.

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

    Awesome explanation

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

    as usual you are the best
    GIO

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

    This was very helpful, I've liked and subscribed !

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

      Glad to hear that, thank you 🙏

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

    This is the best PHP course ever. Thanks a million!

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

    Da best explanation!

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

    Awesome 👏 thanks bro ❤

  • @remotetechie6910
    @remotetechie6910 3 ปีที่แล้ว

    Great explanation!

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

    Really nice tutorial. Thanks a lot

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

    thank u for your efforts

  • @bevedel
    @bevedel 3 ปีที่แล้ว

    Thank you so much Gio. all of your tutorials are awesome and really helpful. waiting for more tutorials from you.
    Is it possible to have more video about advanced laravel?
    Thanks

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

      Thank you. Yes after this PHP series is complete I'll be doing some advanced Laravel

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

    Thanks for creating these tutorials. They are awesome! When it loops and yields the POD statement in Ticket.php, does it make a database query call for each record?

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

      No it does not, the query is executed before that & yield just generates one value at a time without consuming a lot of memory

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

      ​@@ProgramWithGioBut how does it generate it from? Where is the DB data before current() is called? Is it in PHP already? Where is the data from the SELECT * statement?

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

    Thanks again.

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

    Like all video's I've watched in this series, it has been very enlightening and useful. Excellent content. The speed of it is high, but I can pausing and go back, where needed. I have programmed in php for a while, but not much in OOP and this course offers many subjects that I still wanted to learn and not yet have used or understood. It is the best and most complete course that I've found for php.
    Some sideline reactions that pop up:
    When you state that it isn't production ready because of edge cases and such... and I've heard that disclaimer before ... will the course get students to a point solutions can be used in production? It would be nice to at least know how to get solutions to that point.
    I would like this grows to something full stack including js or react, because even WordPress is expanding in that direction more and more. A second course that adds that would be nice too.
    In the first part of the course I learned about the DIRECTORY_SEPARATOR constant, but I have never seen you used that to build paths. Is that in practice a redundant constant that is only used in the basic lessons?

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

      Thank you for the feedback 🙌. To address your points:
      In some videos I teach how certain things work when you take away the abstraction from frameworks. That's why I state that it's better not to use for production and use a well maintained & battle tested library instead. I only teach how it works so that when you transition into framework you understand it better & is easier to work with.
      We are working on a final project now, not sure if you've seen latest videos. That project we will deploy in production. So yes, I show solutions that can be used in production later on in the series when we get to topics like ORMs, templating engines, micro frameworks & so on.
      This course will not be full stack. I don't teach JS/react. For final project I am providing the front-end and we are building the back-end in videos. I want to end the series soon and since this series is all about PHP, I don't want to mix it with front-end too much.
      About the directory separator, yes in most cases it's not needed, it's there for OS differences but in most cases you deploy apps in Linux based production so using slash shouldn't be a problem. Honestly I think it's fine in Windows too, though I haven't tested it. I know that behind the scenes it does slash conversion anyways so the constant may not be needed at all.

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

      @@ProgramWithGio Thank you for answering. I am following the new videos too and the new project you are adding to the course. I'm sure it will be more than enough for me.
      Thank you for sharing the knowledge!

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

      @@ProgramWithGio p.s. I work on a windows machine and never had problems with defining paths like you do, so in practice the constant is probably redundant.

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

    I love your video

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

    What fonts are you using they are great?
    Speciall the joined signs.

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

      It's Darcula theme on phpstorm with default settings

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

    Thankyou sir 🙏🙏

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

    Whats the difference between generators and coroutines, because they seem very similar?

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

      Coroutines can be implemented with generators, its just an interruptible function. It can be used to send values back & from generators. (I intentionally omitted that part from this lesson since it can be confusing for beginners)

  • @sharifurrobin7720
    @sharifurrobin7720 3 ปีที่แล้ว

    Great job

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

    ”Let me reiterate”
    Best NPI ever. 😂

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

    Great video. Too bad we didn't have the access to Ticket database table to test this out on our own.

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

      @@benderbg thank you. It's easy to recreate, only a few columns

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

    Went through again while practicing it. Just beautiful. I have a question that I'm probably asking because I'm considerably new to programing but.. why would one want to or need to rewind an iteration/generator?

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

      You probably would not need to use it since rewind will throw an exception I think if the iteration has begun.

  • @valentindobrica9584
    @valentindobrica9584 3 ปีที่แล้ว

    Finally bro you posted :D

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

    kindly explain how construct method in model class access app::db without using app class in model class,

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

      We covered that in second section within the Models/PDO lesson. Model is abstract class & in constructor it calls static method db on the App class and assigned to property, then any model extending this base model has access to the db proeprty.

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

      Thanks a lot sir

  • @dfejescoding
    @dfejescoding 3 ปีที่แล้ว

    Profissional as always.
    Is it possible to use generators for large video files to stream them?

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

      I have not done video processing or uploading so I'm not 100% sure but you could use generators to process large files so perhaps it's possible with video files as well.

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

    was great hear how do you read the text

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

      Thank you but not sure I understand, what text?

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

    you rocks

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

    my page showing out of memory error even using generators, can you explain why?

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

      kindly reply

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

      It depends on your configuration, maybe memory limit is low. Also might be an issue with the code, hard to say without looking at the code

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

      @@ProgramWithGio class GeneratorExampleController
      {
      public function __construct()
      {

      }
      public function index()
      {
      $numbers = $this->lazyRange(1,3000000);
      foreach ($numbers as $key => $number){
      echo $key .':' . $number . '';
      }

      //phpinfo();
      }
      public function lazyRange(int $start , int $end) :Generator
      {
      for ($i = $start; $i

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

      first it started printing the numbers but after some seconds it shows aw snap, something went wrong while displaying this webpage . error code: out of memory in google chrome

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

      That's just the browser is not able to display/render so much content. You are trying to print 3 million lines of HTML essentially. If you were to display 3 million rows of data on a page it would crash also. You would typically use pagination for that.

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

    Cool

  • @eugenbelousov5027
    @eugenbelousov5027 3 ปีที่แล้ว

    nice

  • @vladje3747
    @vladje3747 3 ปีที่แล้ว

    Who knows PHP better than creators of course ma man Gio )) Gio tell honestly you know Python as well as PHP? I won't believe you not.

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

      Haha, no I don't know Python as well as PHP 😁

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

      @@ProgramWithGio you're too modest bro ) I know that you able to build any application better than 80% of programmers , because you really driven in architecture ☝️

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

      @@vladje3747 thank you but I think anyone can build any app if they put enough effort & time into it 🙂

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

      @@ProgramWithGio And motivation , I'm learning python right now and is really easy to me 😂 after 3years of php , python seems to me like nuts hahaha 😂😂😂

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

      @@vladje3747 nice. Python is great

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

    Bro, I got stumped at timestamp 18:27. Its about the database and data for the tickets table. I could not find them in the repo. Please advise.

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

      It's just dummy data and table I created to demonstrate generators, it doesn't matter what data it will be, you can also create some table and populate it with a lot of records. Just name it tickets.

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

      @@ProgramWithGio I was lazy. Created and tested. Works great. Thank you so much.

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

    Thank you again for such a beautiful explanation for everything you teach ♥ ♥ ♥ ♥ ♥