New OOP Features
in PHP 5.5

Matthew Turland

There Will Be Slides

Publications section of my web site at

Publications section of

I Co/Wrote These

php|architect's Guide to Web Scraping with PHP
PHP Master: Write Cutting-Edge Code


Features of Focus

Full list of 5.5.0 changes

Rick Moranis with a magnifying glass near the end of 'Honey I Shrunk the Kids'

Generators Defined

Generators provide an easy way to implement simple iterators without the overhead or complexity of implementing a class that implements the Iterator interface.

A filled shot glass

Advantages of Generators

Neil Degrasse Tyson badass meme

Disadvantages vs Iterators

Spaghetti Code

How Generators Work

Example lifted from the Generators RFC

Generator class in the PHP manual

How Generators Terminate

An Improved file()

Example also lifted from the Generators RFC

(Hint: You should probably read this thing.)

Iterators vs Generators: Example

Iterators vs Generators: Comparison


Coroutines are like generators in reverse: they consume data.

Coroutines and Exceptions

Generators + Coroutines

Putting It All Together

Analog to Streams

Don't cross the streams: Good advice is timeless

In a Nutshell

Dr. Evil from the Austin Powers movie series

Finally! finally!

Practical Example of finally

Example lifted from the finally RFC

How finally Works
With Exceptions

How finally Works
Without Exceptions

How finally Works
With Returns

finally in a nutshell

Tardis Express: When it absolutely, positively has to be there before you sent it


Example lifted from PHP Manual OOP Basics

Compare with namespaces in other languages

Using ::class with PHPUnit

Examples lifted from Class Name Scalars RFC

Using ::class with Doctrine

Using ::class with Pimple

Using ::class with general PHP

Special ::class Resolutions

::class in a Nutshell

Use in dynamic instantiation of classes

Non-Scalar Keys in foreach

Use Cases for Non-Scalar Keys

Examples lifted from the Non-Scalar Keys RFC

Why Use Non-Scalar Keys?

Where to Find Me

Me at SunshinePHP 2013