Chapter 3. Working with PHP Functional Programming

In this chapter we will cover the following topics:

  • Developing functions
  • Hinting at data types
  • Using return value data typing
  • Using iterators
  • Writing your own iterator using generators

Introduction

In this chapter we will consider recipes that take advantage of PHP's functional programming capabilities. Functional, or procedural, programming is the traditional way PHP code was written prior to the introduction of the first implementation of object-oriented programming (OOP) in PHP version 4. Functional programming is where program logic is encapsulated into a series of discreet functions, which are generally stored in a separate PHP file. This file can then be included in any future scripts, allowing ...

Get PHP 7 Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.