Skip to Content
Mastering PHP 7
book

Mastering PHP 7

by Branko Ajzele
June 2017
Intermediate to advanced
536 pages
9h 49m
English
Packt Publishing
Content preview from Mastering PHP 7

Iterable pseudo-type

Quite often, functions in PHP either accept or return an array or object implementing the \Traversable interface. Though both types can be used in the foreach constructs, fundamentally, an array is a primitive type; objects are not. This made it difficult for functions to reason about these types of iterative parameters and return values.

PHP 7.1 addresses this need by introducing the iterable pseudo-type to the mix. The idea is to use it as a type declaration on a parameter or return type to indicate that the value is iterable. The iterable type accepts any array, any object implementing Traversable, and generators.

The following example demonstrates the use of iterable as a function parameter:

 function import(iterable ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning PHP 7

Learning PHP 7

Antonio L Zapata (GBP)
Upgrading to PHP 5

Upgrading to PHP 5

Adam Trachtenberg

Publisher Resources

ISBN: 9781785882814Supplemental Content