News Feed

News Archive
feed this:

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

Engine Yard Blog:
What to Expect When You're Expecting PHP 7, Part 2
April 08, 2015 @ 11:07:08

The Engine Yard blog has posted the second part of Davey Shafik's "What to Expect with You're Expecting: PHP7" series. In this new post he gets into the details of a few more of the upcoming PHP7 features including generator improvements and engine exceptions.

As you probably already know, PHP 7 is a thing, and it's coming this year! Which makes this as good a time as any to go over what's new and improved. In the first part of this series, we looked at the some of the most important inconsistency fixes coming up in PHP 7 as well as two of the biggest new features. In this post, we take a look another six big features to land in PHP 7 that you'll want to know about.

The features he talks about this time are:

  • Unicode Codepoint Escape Syntax
  • Null Coalesce Operator
  • Bind Closure on Call
  • Group Use Declarations
  • Generator return expressions and delegation
  • Engine Exceptions

He also includes three things you can do to help/get prepared for this upcoming release including testing your code on a PHP7 VM or help out with writing tests and documentation for PHP and its extensions.

0 comments voice your opinion now!
engineyard php7 feature list major unicode coalesceoperator bindclosure groupuse generator engineexception


Christopher Pitt:
Co-operative PHP Multitasking
March 30, 2015 @ 12:47:41

Christopher Pitt has posted a new article on about when an "array is like an adventure" when in the context of co-operative PHP multitasking. In it he shows how to make code work asynchronously with out the use of extensions, only generators.

Last week I got the opportunity to share recent work with my colleagues, at SilverStripe. I was going to present Async PHP today, but since I covered ReactPHP last week; I decided to talk about something slightly different. So here's a post about cooperative multitasking.

He starts with some basic arrays and other things that act like them and can be iterated through (Traversable). He talks about implementing custom iterators to act the same way and the use of IteratorAggregate to "cheat" a bit when making them. The he gets into generators, showing how they can be used to iterate similarly. He shows how it's possible to send data to a generator, throwing exceptions inside them and the use of "coroutines" to create asynchronous code. He builds up a queue system with this method and shows how they execute with some simple echo output. He also shows the use of RecoilPHP, another coroutine-based library, to replace the main kernel for a ReactPHP script. He also mentions IcicleIO as another option.

0 comments voice your opinion now!
cooperative multitasking asynchronous code coroutine generator


Paul Jones:
Bookdown DocBook-Like HTML Output From Markdown
March 05, 2015 @ 10:49:27

Paul Jones has posted about a new tool he's worked up specifically for authors looking to write using Markdown and wanting it to generate out like DocBook results. His tool, Bookdown, uses Markdown and JSON files instead of XML configurations.

Yes, I know, there's a ton of static site generators for PHP out there already [...but they're] not DocBook-like documentation. By "DocBook-like", I mean (among other things) numbered headers, auto-generated tables-of-contents on their own pages, hierarchical multi-page presentation, and the next/previous/up linking at the top and bottom of pages.

[...] So: Bookdown. This scratches my particular itch, with very few dependencies. Bookdown, although it can be used as a site generator, is only incidentally a site generator. What it really is is a page generator, with the idea that you can integrate the pages into any other site you want.

The library is separate from the project and is written to use a dependency injection methodology to keep things decoupled and well-structured. If this sounds interesting either for personal use or if you'd like to check out the code, head over to the project site for more information.

0 comments voice your opinion now!
markdown bookdown library project docbook output static generator


Edd Mann:
Implementing Streams in PHP
January 16, 2015 @ 10:09:22

Edd Mann has a new post today looking at implementing streams in your PHP applications. In this case we're not talking about the streams built into PHP but the concept of a source of information that only produces the next item when requested (aka "lazy loading").

Typically, when we think about a list of elements we assume there is both a start and finite end. In this example the list has been precomputed and stored for subsequent traversal and transformation. If instead, we replaced the finite ending with a promise to return the next element in the sequence, we would have the architecture to provide infinite lists. Not only would these lists be capable of generating infinite elements, but they would also be lazy, only producing the next element in the sequence when absolutely required. This concept is called a Stream, commonly also referred to as a lazy list, and is a foundational concept in languages such as Haskell.

He talks about how streams of data should be interacted with differently than a finite list of data and the promises they're based on to provide the right data. He shows two different approaches to implementing a an object to stream data from - a class-based method and one that uses generators. Sample code is provided for each with the generator approach being a bit shorter as they're designed to lazy load items as requested.

0 comments voice your opinion now!
stream data lazyload generator class iterator tutorial

How to use the "yield" keyword in PHP 5.5 and up
May 23, 2014 @ 12:09:47

In a recent post to the LeaseWebLabs blog Maurits van der Schee looks at the use of the "yield" keyword in PHP 5.5 to work with generators. A generator is very similar to a function that returns an array, in that a generator has parameters, can be called, and generates a sequence of values but it yields values one at a time.

The concept of generators is not new. The "yield" keyword exists in other programming languages as well. As far as I know C#, Ruby, Python, and JavaScript have this keyword. The first usage that comes to mind for me is when I want to read a big text file line-by-line (for instance a log file). Instead of reading the whole text file into RAM you can use an iterator and still have a simple program flow containing a "foreach" loop that iterates over all the lines.

He includes a few code examples showing a class that can read in data from a file in chunks and output the lines as they're extracted (versus using something like file). He also talks about a small performance comparison in working with the file pointer, fread over fgets. He even makes a simple benchmark script to compare the overall time and memory consumption of the fetching of different byte "chunks" from the file.

0 comments voice your opinion now!
yield generator file read fread fgets memory time benchmark

Generators in PHP
August 06, 2013 @ 12:25:50

On a tutorial has been posted talking about one of the newer features in PHP - generators. In the tutorial Stefan Froelich walks you through how they work and a few examples of their use.

Generators in PHP If you've followed my previous posts about iterators then you'll know that iteration is an important programming concept, but implementing the required interfaces to create an iterable object can be a hassle at best because of the amount of boilerplate code that is required. With the release of PHP 5.5, we finally have generators!

He starts with a more practical example - pulling lines from a file, one at a time, without the overhead of having to read in the entire file at once. He also includes an example of returning the keys from the generator (not just the value) and injecting values with the "send" method.

0 comments voice your opinion now!
generator tutorial introduction example yield inject keys


Blake Gardner:
Practical usage of PHP 5.5 generators yield keyword
June 24, 2013 @ 11:54:42

With the release of PHP 5.5 came a whole group of new features, including the "yield" keyword for better handling of values in iteration. Blake Gardner has posted a practical example of its use to his site today.

The key to understating the way the yield works verses a normal function is that rather than generating all of your data and returning the final array when it's done; you yield the value as it's generated. The state of the generator function is saved after you yield and then its state is restored when called again so the iteration can continue.

He shows a basic use of "yield" in a simple foreach of 1000000 values. In the first example, memory is exhausted and the second yields the values as they come, reducing the overhead significantly. The "range_yield" function returns them as the "for" loop generates them.

0 comments voice your opinion now!
yield feature practical use tutorial generator


Lorna Mitchell:
Simplest PHP Generator Example
May 23, 2013 @ 10:31:02

On her blog Lorna Mitchell has posted an example of a basic generator written in PHP, a feature of the upcoming PHP version 5.5.

I really like the generators feature that's arriving in PHP 5.5, and since we're now into release candidate releases, it's actually not that far away. I've been speaking on this topic and I thought I'd share my trivially simple code example from my slides.

She includes an example of a very basic generator using the new "yield" keyword and how to implement it in a simple foreach loop. There's also a little talk about when is a good time to use generators in your applications (two examples: complex number calculation and working with large data sets a chunk at a time). For more information on how these generators will work, check out this page in the PHP manual.

0 comments voice your opinion now!
generator simple example introduction manual

Pro Workflow in Laravel and Sublime Text
March 15, 2013 @ 09:48:39 has a new article today for the Laravel developers out there (an up and coming PHP framework) with some handy Sublime Text tips you can use to streamline your workflow.

Not too long ago, I built a handful of generators for Laravel, which ease the process of various tasks. Today, thanks to help from Gaurav Narula, we're turning things up a notch with the release of a new Sublime Text plugin that leverages the power of Artisan and the generators from directly within your editor.

They help you get it installed and running and show (via a screencast) the steps to use it when working in your code. Their examples show the creation of resources (all MVC aspects and configurations), working with Artisan commands, migrations and other bits of code.

0 comments voice your opinion now!
laravel sublimetext editor package generator plugin

Nikita Popov:
Cooperative multitasking using coroutines (in PHP!)
December 24, 2012 @ 09:46:36

Nikita Popov has a new post to his blog about a new feature that will be coming in PHP 5.5 and how to use them, coroutines and generators, in an example application.

Coroutines on the other hand have received relatively little attention. The reason is that coroutines are both a lot more powerful and a lot harder to understand and explain. In this article I'd like to guide you through an implementation of a task scheduler using coroutines, so you can get a feeling for the stuff that they allow you to do. I'll start off with a few introductory sections. If you feel like you already got a good grasp of the basics behind generators and coroutines, then you can jump straight to the "Cooperative multitasking" section.

He starts with a look at generators, a piece of functionality that will allow PHP to, for example, more easily create iterators "on the fly." He then moves on to coroutines, added functions that you have two-way communication with generators instead of just pulling data from them. With the basics out of the way, he gets into the "cooperative multitasking" and a sample socket-based server he implements using some of the concepts.

0 comments voice your opinion now!
generator coroutine multitasking server socket tutorial

Community Events

Don't see your event here?
Let us know!

opinion release example application introduction api voicesoftheelephpant version laravel series podcast interview framework php7 library symfony2 community composer conference performance

All content copyright, 2015 :: - Powered by the Solar PHP Framework