If you’re reading this, you’re probably already aware of just how useful PHP’s Generators are for improving performance and/or reducing memory overheads while keeping your code clean and easy to read. We can use a simple
foreach() in the main body of our code, as though iterating over an array, but without the overheads of needing to actually build an array. The Generator itself handles a lot of the boilerplate that we’d otherwise have to write, which also means that we create simpler, cleaner code.
Unlike their equivalent in some programming languages, PHP’s Generators allow you to send data into the Generator itself; not simply at initialisation (the arguments that we pass to the Generator when instantiating it); but also between iterations. This has its own uses, and again, allows us to move code from our main blocks and methods into the Generator itself.
Less commonly recognised is that we can combine these two features, creating Generators that can be used to provide data for our main code block and methods, while allowing us to send data to the Generator that can actually modify its behaviour dependent on circumstance.
However, there are a few “gotchas” when we combine Generators that both return and accept data in this way, and it really helps to be aware of them when we’re developing, otherwise it can create problems.
Posted in PHP
Tagged Generator, PHP
It’s been a long, slow, lazy summer; but it feels as though things are accelerating in my life at the moment as we approach the launch of the PHPDiversity kickstarter. Mark promised himself that he wouldn’t proceed until he had all the costs associated with making me a reality (and knew that I was financially viable), and until he’d held the prototype me in his hands (rather than simply seen photographs of me) to assess that I really was what he’d expected.
Well, he’s been able to put those final figures into his spreadsheets now; and the prototype me is on its way to him even as I type. Assuming that it matches his expectations, he reckons that the kickstarter to make me real will launch toward the end of this month (October) or early November at the latest.
Enfys, the PHP Rainbow Elephpant, is intended to help promote Diversity within the PHP Community: but what exactly is Diversity? What are the benefits of Diversity? And how can Diversity be achieved?
I’m reminded that it has been quite a while since I last posted anything here on Mark’s blog site, and that people might be forgetting about me… but an Elephpant never forgets. I’m still in a fever-pitch of excitement, as I have been ever since I first saw those photographs of the real me. But Elephpants are also patient: when Mark was originally talking about a kickstarter to help fund me into reality, he was expecting it to happen around October. Then the first photographs of me were sent from the factory in China, and he was hopeful that the timescales could be brought forward; but things do seem to have been moving slowly over the Summer, so it’s likely that it will be in October. However, whether it’s in September or October, it is certain that it will be going ahead before very long. All the costings are looking good so far
In the meanwhile, I’ve been keeping myself occupied playing Pokemon Go, and watching the Olympic games. “Citius, Altius, Fortius”, “Faster, Higher, Stronger”… you humans can really achieve quite incredible feats of skill, agility, power and endurance.
“A week is a long time in politics”, apparently. I’m not sure what that means: every time I’ve asked Mark over the last week or so, he’s been reduced almost to tears, mumbling something about “being proud to be a European”, but “no longer allowed to say so out loud”.
But what I do know is that a lot can happen in just one week; and a lot has been happening here, as Mark starts to put together costings and estimates in spreadsheets. The pictures that I posted last week show that it’s technically feasible to create me as a real Elephpant, and prove that there will always be at least one of me. Now he’s putting some numbers and costings together to show whether or not I’m financially viable; and he tells me that it’s all looking good so far, though he needs some more numbers to be certain. And it will need at least 1,200 of me to work, because that’s the minimum run that the factory will do; but I shouldn’t cost much more than any of the other Elephpants out in the world, despite the extra overheads of the colouring process.
That’s all very good news for me. It’s important that there are lots of me all around the world, spreading the Diversity message wherever they find themselves.
Mark’s away at the Dutch PHP Conference where (apparently) he’s talking to people about cats; but while he’s away, I’ve had the most incredible, incredible news. It’s really been a very busy day here.
Not only is there a new PHP User Group in Denmark, PHPJutland, that’s only just been announced today – waving “hello” to all my new Danish friends; and I have a new cousin to welcome to the family of Elephpants; but I’ve also seen the real me… I mean, I haven’t actually seen the “real” me yet (my eyesight isn’t good enough to see half way round the world, and the real me is still at the factory in China), but I have seen photographs of the real me, and that’s nearly as good, because it means that a real me now exists in the real world. I am now officially a prototype!
And I’m so excited about seeing me for the first time ever, that I just have to share some of the photographs with you all to show you what I look like.
Wow! Mark is letting me write my own posts on his blog.
For those of you who don’t know me yet, I’m Enfys, the PHP Diversity Rainbow Elephpant; or at least, I shall be when I’m real. At the moment, I’m just a virtual Elephpant, an idea inpired by a photoshopped picture by Peter Kokot (a Slovenian developer); but someday soon I hope to be a real Elephpant, and join the PHP worldwide herd.
And yesterday, my dream came a step closer to reality.