PHP is experiencing a renaissance, though it may be difficult to tell with all of the outdated PHP tutorials online. With this practical guide, you’ll learn how PHP has become a full-featured, mature language with object-orientation, namespaces, and a growing collection of reusable component libraries.

Author Josh Lockhart—creator of PHP The Right Way, a popular initiative to encourage PHP best practices—reveals these new language features in action. You’ll learn best practices for application architecture and planning, databases, security, testing, debugging, and deployment. If you have a basic understanding of PHP and want to bolster your skills, this is your book.

Learn modern PHP features, such as namespaces, traits, generators, and closures

Discover how to find, use, and create PHP components

Follow best practices for application security, working with databases, errors and exceptions, and more

Explore Facebook’s HVVM and Hack language implementations—and how they affect modern PHP

Build a local development environment that closely matches your production server

Language Features

Chapter 1The New PHP

Past

Present

Future

Chapter 2Features

Namespaces

Code to an Interface

Traits

Generators

Closures

Zend OPcache

Built-in HTTP server

What’s Next

Good Practices

Chapter 3Standards

PHP-FIG to the Rescue

Framework Interoperability

What Is a PSR?

PSR-1: Basic Code Style

PSR-2: Strict Code Style

PSR-3: Logger Interface

PSR-4: Autoloaders

Chapter 4Components

Why Use Components?

What Are Components?

Components Versus Frameworks

Find Components

Use PHP Components

Create PHP Components

Chapter 5Good Practices

Sanitize, Validate, and Escape

Passwords

Dates, Times, and Time Zones

Databases

Multibyte Strings

Streams

Errors and Exceptions

Deployment, Testing, and Tuning

Chapter 6Hosting

Shared Server

Virtual Private Server

Dedicated Server

PaaS

Choose a Hosting Plan

Chapter 7Provisioning

Our Goal

Server Setup

PHP-FPM

nginx

Automate Server Provisioning

Delegate Server Provisioning

Further Reading

What’s Next

Chapter 8Tuning

The php.ini File

Memory

Zend OPcache

File Uploads

Max Execution Time

Session Handling

Output Buffering

Realpath Cache

Up Next

Chapter 9Deployment

Version Control

Automate Deployment

Capistrano

Further Reading

What’s Next

Chapter 10Testing

Why Do We Test?

When Do We Test?

What Do We Test?

How Do We Test?

PHPUnit

Continuous Testing with Travis CI

Further Reading

What’s Next

Chapter 11Profiling

When to Use a Profiler

Types of Profilers

Xdebug

XHProf

New Relic Profiler

Blackfire Profiler

Further Reading

What’s Next

Chapter 12HHVM and Hack

HHVM

The Hack Language

Further Reading

Chapter 13Community

Local PUG

Conferences

Mentoring

Stay Up-to-Date

Appendix Installing PHP

Appendix Local Development Environments

Title:

Modern PHP

By:

Josh Lockhart

Publisher:

O'Reilly Media

Formats:

Print

Ebook

Safari Books Online

Print:

February 2015

Ebook:

February 2015

Pages:

268

Print ISBN:

978-1-4919-0501-2

| ISBN 10:

1-4919-0501-8

Ebook ISBN:

978-1-4919-0498-5

| ISBN 10:

1-4919-0498-4

Josh Lockhart

Josh Lockhart is the creator of the Slim Framework for PHP. He also created and maintains PHP The Right Way, a popular initiative in the PHP community to encourage best practices and provide quality information. Josh is a senior developer at New Media Campaigns, a full service web design, development, and marketing agency in Carrboro, North Carolina.

Colophon

The animal on the cover of Modern PHP is a straw-necked ibis (Threskiornis spinicollis).It can be found throughout Australia, New Guinea, and parts of Indonesia.Straw-necked ibises are large birds, growing up to 30 inches long. The distinctive stifffeathers on the neck from which the bird gets its name appear during adulthood.They have long, curved beaks that help them sift through water for insects, mollusks,and frogs. Farmers welcome straw-necked ibises in their fields because the birds willeat insects, grasshoppers, crickets and locusts that would have otherwise destroyedcrops.

These birds are very nomadic, and travel in flocks between habitats. They favor shallowfreshwater wetlands, cultivated pastures, swamps, lagoons, and grasslands. Duringbreeding season, these ibises will build a large, cup-shaped nest of sticks and reedshigh up in trees over water. They are also known to nest in colonies, often togetherwith the Australian white ibis. For this reason, they are easily spotted standing in thehigh branches of bare trees, creating a striking silhouette against the sky.