Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Niklas Keller:
An Introduction to Generators in PHP
Sep 21, 2017 @ 17:57:15

In a post to his site Niklas Keller provides an introduction to generators in PHP. Generators provide more "just in time" functionality for looping (iterators) without the need to create a separate class to handle it.

Generators have been added to PHP in version 5.5, yet the have received rather low attention. The PHP 5.5 migration guide introduced them as way to implement simple iterators.

He shows the comparison of generators versus a foreach loop and discusses how the yield statement works and what benefits the generator gives over normal looping. He refactors the example to get a clearer picture into what's happening inside the generator, outputting a few strings when the next value is fetched. He then suggests that generators that are just used as iterators are "boring" and covers some more interesting features and uses (including handling of async operations).

tagged: generator tutorial introduction yield async looping interator

Link: http://blog.kelunik.com/2017/09/14/an-introduction-to-generators-in-php.html

Jani Hartikainen:
Parsing and evaluating PHP in Haskell: Part 2
Jan 23, 2013 @ 17:24:34

Jani Hartikainen has posted the second article in his series looking at parsing PHP with Haskell (part one is here). In this new article he builds on the parser he built last time and gets to the actual evaluation of the PHP code.

Last week I wrote a post about a PHP parser / evaluator I wrote in Haskell. I explained some of the parts on how the parser itself was designed to process PHP code into an abstract source tree. Continuing from where we left off in the previous part, in this post I’ll discuss the actual evaluation part.

He starts by introducing the structure of the evaluator script, how it's broken up into functionality based on the type of object/data type being handled. He uses a "custom monad transformer stack" to handle the environment for the evaluation as is progresses. He talks about handling statements and expressions, declaring custom functions and the actual execution of the function call. There's also a mention of handling conditionals/looping as well as dealing with PHP's type juggling.

if you're interested in seeing the final result (and maybe trying it out for yourself) you can find the full source on Github.

tagged: haskell parse evaluate monad transformer functions expressions looping typejuggling

Link:

PHPFreaks.com:
PHP Loops
Jun 20, 2008 @ 17:10:18

The PHPFreaks.com website gets back to basics with a new tutorial they've posted - a look at looping in PHP.

Looping is simply a way for you to reduce the amount of code and/or content you have to write out. The idea is that you have something you have to do, or some content you have to show, and instead of just "writing it all out," you find a pattern to it - a common denominator - and let PHP execute the code or generate the content piece by piece using that pattern, based on a condition.

Their example solves the problem of finding taking a range of numbers and seeing how many of them can be evenly divided by another number.

tagged: looping conditional structure tutorial example

Link:

Stefan Mischook's Blog:
PHP Video Tutorial: PHP Loops
Sep 27, 2007 @ 16:15:00

Stefan Mischook has posted another video introducing beginning PHP developers to the basics of the language. In this new video, he explains looping.

I've released a new video tutorial covering PHP basics. In this video I teach three different loop types in PHP: For Loops, While Loops and Foreach Loops.

You can watch this video here or check out some of the other video tutorials he has posted on everything from conditionals to working with objects.

tagged: video tutorial looping introduction beginner video tutorial looping introduction beginner

Link:

Stefan Mischook's Blog:
PHP Video Tutorial: PHP Loops
Sep 27, 2007 @ 16:15:00

Stefan Mischook has posted another video introducing beginning PHP developers to the basics of the language. In this new video, he explains looping.

I've released a new video tutorial covering PHP basics. In this video I teach three different loop types in PHP: For Loops, While Loops and Foreach Loops.

You can watch this video here or check out some of the other video tutorials he has posted on everything from conditionals to working with objects.

tagged: video tutorial looping introduction beginner video tutorial looping introduction beginner

Link:


Trending Topics: