Leanpub Header

Skip to main content

PHP 7 Upgrade Guide

Your guide to new features, breaking changes, and more.

Learn about ALL of the new features and breaking changes in PHP 7! This book also includes instructions on how to install PHP 7 on various platforms.

A portion of all proceeds are donated to  Open Sourcing Mental Illness!

Like this book? Review it on GoodReads!

Free With Membership

With Membership

Free!

$7.99

You pay

$7.99

Author earns

$4.47

Cause gets

$1.92
$

...Or Buy With Credits!

You can get credits monthly with a Reader Membership
PDF
EPUB
WEB
419
Readers
142
Pages
About

About

About the Book

The PHP 7 release is here, bringing some much-desired changes and improvements to the language.   This book covers all of the new features coming in PHP 7, as well as breaking changes and "gotchas" to watch out for.  You'll learn how to take advantage of these changes and get started with PHP 7 today.

Who is this book for?

This book is for PHP developers looking to jump into PHP 7.  You'll need previous experience with PHP in order to understand the topics and examples we'll cover.  The more you know about PHP 5 and OOP, the more you'll understand why some of the changes are important and how they'll impact your development.

If you're a manager or leader of a team looking to work in PHP 7, this book will help your developers quickly catch up on all the changes they need to know about, and even expose some new features they can take advantage of for faster, better development.

Author

About the Author

Colin O'Dell

Colin O'Dell is a Lead Web Developer at Unleashed Technologies, a web and hosting firm based in Maryland. He has been programming since 1996 and has over a decade of professional experience with PHP. In addition to being an active member of the PHP League and maintainer of the league/commonmark parser, Colin is also a conference speaker, author, Symfony Certified Developer (Expert), and Magento Certified Developer.

Contents

Table of Contents

Preface

Who is this book for

Contents

Other resources

Acknowledgements

  1. PHP Wiki and Documentation Content
  2. Getting Started with PHP 7
  3. PHP 5 Conflicts

Ubuntu 14.04 and 16.04+

Debian 8 & 9

Debian 6 & 7

CentOS / RHEL

Mac OS X

Windows

phpbrew

Docker

Vagrant Image

Build from Source

  1. Part 1 - New Features

Chapter 1: Scalar Type Hints

  1. Type Checking Modes
  2. Be careful where you place declare
  3. TypeError
  4. Mixing Modes
  5. Backwards Compatibility
  6. Further Reading

Chapter 2: Return Type Declarations

  1. Returning null
  2. Sub-Class Methods
  3. Further Reading

Chapter 3: Combined Comparison (Spaceship) Operator

  1. Comparing Values
  2. Sorting
  3. Sorting by multiple values
  4. Further Reading

Chapter 4: Null Coalesce Operator

  1. Differences From ?:
  2. False Values
  3. Chaining
  4. Further Reading

Chapter 5: Unicode Codepoint Escape Syntax

  1. String encoding
  2. Why the {}s?
  3. Limitations
  4. Backwards Compatibility
  5. Further Reading:

Chapter 6: Anonymous Classes

  1. Nesting Classes
  2. Use Cases
  3. Differences from Named Classes
  4. Further Reading:

Chapter 7: Group Use Declarations

  1. Compound Namespaces
  2. Further Reading:

Chapter 8: Closure call Method

  1. Further Reading:

Chapter 9: Generator Return Expressions

  1. Wait, what are generators?
  2. Further Reading:

Chapter 10: Generator Delegation

  1. Yielding Values
  2. Sending Values
  3. Exceptions
  4. Return Values
  5. Further Reading:

Chapter 11: Reliable User-land CSPRNG

  1. Why not use rand or mt_rand?
  2. Backwards Compatibility
  3. Forwards Compatibility
  4. Further Reading

Chapter 12: Integer Division

  1. Backwards Compatibility
  2. Further Reading

Chapter 13: preg_replace_callback_array

  1. Backwards Compatibility
  2. Further Reading

Chapter 14: IntlChar Class

  1. Backwards Compatibility
  2. Further Reading
  3. Part 2 - Language Changes & Improvements

Chapter 15: Performance

  1. Further Reading

Chapter 16: Language Consistency

  1. Uniform Variable Syntax
  2. Abstract Syntax Tree
  3. Further Reading

Chapter 17: Semi-Reserved Words

  1. Further Reading

Chapter 18: Error Handling and Exceptions

  1. Exceptions in the Engine
  2. Catching Error Objects
  3. Reclassification of E_STRICT Notices
  4. Backwards Compatibility
  5. Further Reading

Chapter 19: Expectations

  1. Don’t rely on assertion behavior
  2. assert() as a statement
  3. Custom errors
  4. Avoid catching AssertionErrors
  5. Configuration
  6. Backwards Compatibility
  7. Further Reading

Chapter 20: Array Constants in define()

  1. Further Reading

Chapter 21: Filtered unserialize()

  1. Secure filtering
  2. Examples
  3. Further Reading

Chapter 22: session_start Options

  1. New options
  2. Further Reading

Chapter 23: Reflection Enhancements

  1. ReflectionGenerator
  2. ReflectionType
  3. ReflectionParameter
  4. ReflectionFunctionAbstract
  5. Backwards Compatibility
  6. Further Reading

Chapter 24: Integer Semantics

  1. Casting NaN and Infinity
  2. Negative bitwise shifting
  3. Bitwise shifting too far
  4. Backwards Compatibility
  5. Further Reading

Chapter 25: Division By Zero Semantics

  1. Backwards Compatibility
  2. Further Reading

Chapter 26: JSON Library

  1. Fractional float values
  2. Backwards Compatibility
  3. Further Reading

Chapter 27: Behavior Changes to foreach

  1. Changes
  2. Backwards Compatibility
  3. Further Reading

Chapter 28: Behavior Changes to list

  1. String Handling
  2. Empty List Assignment
  3. Variable Assignment Order
  4. Backwards Compatibility
  5. Further Reading

Chapter 29: Parameter Handling Changes

  1. Duplicate Parameter Names
  2. func_get_arg() and func_get_args()
  3. Backwards Compatibility
  4. Further Reading

Chapter 30: Custom Session Handler Return Values

  1. Backwards Compatibility
  2. Further Reading

Chapter 31: Errors on Invalid Octal Literals

  1. Backwards Compatibility
  2. Further Reading
  3. Part 3 - Deprecations & Removals

Chapter 32: Deprecation of PHP 4 Constructors

  1. Backwards Compatibility
  2. Further Reading

Chapter 33: Deprecation of Salt Option for password_hash()

  1. Further Reading

Chapter 34: Removal of Previously-Deprecated Features

  1. Removed Extensions
  2. Removed Language Features
  3. Removed Functions
  4. Removed INI Options
  5. Miscellaneous Removed Functionality
  6. Backwards Compatibility
  7. Tip: Check For Deprecation Warnings
  8. Further Reading

Chapter 35: Removal of Alternative PHP Tags

  1. Migrating From Alternative Tags
  2. Backwards Compatibility
  3. Further Reading

Chapter 36: Reclassification and Removal of E_STRICT Notices

  1. Examples
  2. Same (compatible) property in two used traits
  3. Accessing static property non-statically
  4. Only variables should be assigned by reference
  5. Only variables should be passed by reference
  6. Calling non-static methods statically
  7. Backwards Compatibility
  8. Further Reading

Chapter 37: Removal of Multiple Defaults in Switches

  1. Backwards Compatibility
  2. Further Reading

Chapter 38: Removal of Numeric Hexadecimal String Support

  1. Backwards Compatibility
  2. Further Reading

Chapter 39: Removal of Dead SAPIs and Extensions

  1. Dead SAPIs
  2. Dead Extensions
  3. Backwards Compatibility
  4. Further Reading

Chapter 40: Removal of the date.timezone Warning

  1. Further Reading
  2. Appendix - Backward Compatibility Breaks

Language Changes

  1. Variable handling
  2. list() behavior
  3. foreach behavior
  4. Parameter handling
  5. Integer handling
  6. String handling
  7. Error handling
  8. Other language changes

Standard Library Changes

Other Changes

  1. Curl
  2. Date
  3. DBA
  4. GMP
  5. Intl
  6. libxml
  7. Mcrypt
  8. Session
  9. Opcache
  10. OpenSSL
  11. PCRE:
  12. PDO_pgsql:
  13. Standard:
  14. JSON:
  15. Stream:
  16. XSL:

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

Causes

Causes Supported

Open Sourcing Mental Illness, Ltd

Open Sourcing Mental Illness, Ltd OSMI

Changing how we talk about mental health in the tech community.

https://osmihelp.org
Changing how we talk about mental health in the tech community.
Open Sourcing Mental Illness is a non-profit, 501c3 corporation dedicated to raising awareness, educating, and providing resources to support mental wellness in the tech and open source communities. OSMI began in 2013 as a speaking campaign by Ed Finkler. Ed started speaking at tech conferences about his personal experiences as a web developer and open source advocate with a mental health disorder. The response was overwhelming, and Ed has continued to speak, gather data, and organize efforts to change experiences of those with mental health disorders in the tech workplace. This includes speaking at conferences and companies, conducting research, and creating documentation to assist companies in making supportive environments for those impacted by mental health disorders. He is assisted in these efforts by selfless volunteers who bring their time and expertise to bear on this important issue.

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $14 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub