PHP 7 Upgrade Guide
PHP 7 Upgrade Guide
Your guide to new features, breaking changes, and more.
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.
Reader Testimonials

Larry E. Masters
Founder of CakePHP
Good quick read for those interested in PHP 7. Spend a few bucks and get it.

Jack Fruh
Co-Host, Laravel News Podcast
Just skimming through the PHP 7 Upgrade Guide and am REALLY impressed with the coverage of the new stuff in here - it goes way deeper than I thought, and is showing me things about PHP 7 that I didn't know about. There's been so much talk about PHP 7 being faster, and maybe even some "Just drop it in" mentality without discussion of the actual differences. I think this is going to be a really valuable resource for people - It should be required reading for all PHP devs!
Ian
/u/AfterNite
[The book] looks pretty well written. Examples are simple but to the point.
aquanutz
This book is great. Highly recommend it for those about to go through the upgrade to PHP 7.
Table of Contents
-
Preface
- Who is this book for
- Contents
- Other resources
-
Acknowledgements
- PHP Wiki and Documentation Content
-
Getting Started with PHP 7
- 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
-
Part 1 - New Features
-
Chapter 1: Scalar Type Hints
- Type Checking Modes
- Mixing Modes
- Backwards Compatibility
- Further Reading
-
Chapter 2: Return Type Declarations
-
Returning
null
- Sub-Class Methods
- Further Reading
-
Returning
-
Chapter 3: Combined Comparison (Spaceship) Operator
- Comparing Values
- Sorting
- Sorting by multiple values
- Further Reading
-
Chapter 4: Null Coalesce Operator
-
Differences From
?:
- Chaining
- Further Reading
-
Differences From
-
Chapter 5: Unicode Codepoint Escape Syntax
-
Why the
{}
s? - Limitations
- Backwards Compatibility
- Further Reading:
-
Why the
-
Chapter 6: Anonymous Classes
- Nesting Classes
- Use Cases
- Differences from Named Classes
- Further Reading:
-
Chapter 7: Group Use Declarations
- Compound Namespaces
- Further Reading:
-
Chapter 8: Closure
call
Method- Further Reading:
-
Chapter 9: Generator Return Expressions
- Further Reading:
-
Chapter 10: Generator Delegation
- Yielding Values
- Sending Values
- Exceptions
- Return Values
- Further Reading:
-
Chapter 11: Reliable User-land CSPRNG
- Backwards Compatibility
- Forwards Compatibility
- Further Reading
-
Chapter 12: Integer Division
- Backwards Compatibility
- Further Reading
-
Chapter 13: preg_replace_callback_array
- Backwards Compatibility
- Further Reading
-
Chapter 14:
IntlChar
Class- Backwards Compatibility
- Further Reading
-
Chapter 1: Scalar Type Hints
-
Part 2 - Language Changes & Improvements
-
Chapter 15: Performance
- Further Reading
-
Chapter 16: Language Consistency
- Uniform Variable Syntax
- Abstract Syntax Tree
- Further Reading
-
Chapter 17: Semi-Reserved Words
- Further Reading
-
Chapter 18: Error Handling and Exceptions
- Exceptions in the Engine
-
Reclassification of
E_STRICT
Notices - Backwards Compatibility
- Further Reading
-
Chapter 19: Expectations
-
assert()
as a statement - Custom errors
- Configuration
- Backwards Compatibility
- Further Reading
-
-
Chapter 20: Array Constants in
define()
- Further Reading
-
Chapter 21: Filtered
unserialize()
- Secure filtering
- Examples
- Further Reading
-
Chapter 22:
session_start
Options- New options
- Further Reading
-
Chapter 23: Reflection Enhancements
- ReflectionGenerator
- ReflectionType
- ReflectionParameter
- ReflectionFunctionAbstract
- Backwards Compatibility
- Further Reading
-
Chapter 24: Integer Semantics
- Casting NaN and Infinity
- Negative bitwise shifting
- Bitwise shifting too far
- Backwards Compatibility
- Further Reading
-
Chapter 25: Division By Zero Semantics
- Backwards Compatibility
- Further Reading
-
Chapter 26: JSON Library
- Fractional float values
- Backwards Compatibility
- Further Reading
-
Chapter 27: Behavior Changes to
foreach
- Changes
- Backwards Compatibility
- Further Reading
-
Chapter 28: Behavior Changes to
list
- String Handling
- Empty List Assignment
- Variable Assignment Order
- Backwards Compatibility
- Further Reading
-
Chapter 29: Parameter Handling Changes
- Duplicate Parameter Names
-
func_get_arg()
andfunc_get_args()
- Backwards Compatibility
- Further Reading
-
Chapter 30: Custom Session Handler Return Values
- Backwards Compatibility
- Further Reading
-
Chapter 31: Errors on Invalid Octal Literals
- Backwards Compatibility
- Further Reading
-
Chapter 15: Performance
-
Part 3 - Deprecations & Removals
-
Chapter 32: Deprecation of PHP 4 Constructors
- Backwards Compatibility
- Further Reading
-
Chapter 33: Deprecation of Salt Option for
password_hash()
- Further Reading
-
Chapter 34: Removal of Previously-Deprecated Features
- Removed Extensions
- Removed Language Features
- Removed Functions
- Removed INI Options
- Miscellaneous Removed Functionality
- Backwards Compatibility
- Further Reading
-
Chapter 35: Removal of Alternative PHP Tags
- Migrating From Alternative Tags
- Backwards Compatibility
- Further Reading
-
Chapter 36: Reclassification and Removal of E_STRICT Notices
- Examples
- Same (compatible) property in two used traits
- Accessing static property non-statically
- Only variables should be assigned by reference
- Only variables should be passed by reference
- Calling non-static methods statically
- Backwards Compatibility
- Further Reading
-
Chapter 37: Removal of Multiple Defaults in Switches
- Backwards Compatibility
- Further Reading
-
Chapter 38: Removal of Numeric Hexadecimal String Support
- Backwards Compatibility
- Further Reading
-
Chapter 39: Removal of Dead SAPIs and Extensions
- Dead SAPIs
- Dead Extensions
- Backwards Compatibility
- Further Reading
-
Chapter 40: Removal of the
date.timezone
Warning- Further Reading
-
Chapter 32: Deprecation of PHP 4 Constructors
-
Appendix - Backward Compatibility Breaks
-
Language Changes
- Variable handling
-
list()
behavior -
foreach
behavior - Parameter handling
- Integer handling
- String handling
- Error handling
- Other language changes
- Standard Library Changes
-
Other Changes
- Curl
- Date
- DBA
- GMP
- Intl
- libxml
- Mcrypt
- Session
- Opcache
- OpenSSL
- PCRE:
- PDO_pgsql:
- Standard:
- JSON:
- Stream:
- XSL:
-
Language Changes
- Notes
Causes Supported

Open Sourcing Mental Illness, Ltd
Changing how we talk about mental health in the tech community.
https://osmihelp.orgChanging how we talk about mental health in the tech community.
Authors have earned$10,089,287writing, publishing and selling on Leanpub, earning 80% royalties while saving up to 25 million pounds of CO2 and up to 46,000 trees.
Learn more about writing on Leanpub
The Leanpub 45-day 100% Happiness Guarantee
Within 45 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms
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), EPUB (for phones and tablets) and MOBI (for 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
Top Books
C++20
Rainer GrimmC++20 is the next big C++ standard after C++11. As C++11 did it, C++20 changes the way we program modern C++. This change is, in particular, due to the big four of C++20: ranges, coroutines, concepts, and modules.
The book is almost daily updated. These incremental updates ease my interaction with the proofreaders.
A Guide to Artificial Intelligence in Healthcare
Dr. Bertalan MeskoCan we stay human in the age of A.I.? To go even further, can we grow in humanity, can we shape a more humane, more equitable and sustainable healthcare? This e-book aims to prepare healthcare and medical professionals for the era of human-machine collaboration. Read our guide to understanding, anticipating and controlling artificial intelligence.
C++ Best Practices
Jason TurnerLevel up your C++, get the tools working for you, eliminate common problems, and move on to more exciting things!
Atomic Kotlin
Bruce Eckel and Svetlana IsakovaFor both beginning and experienced programmers! From the author of the multi-award-winning Thinking in C++ and Thinking in Java together with a member of the Kotlin language team comes a book that breaks the concepts into small, easy-to-digest "atoms," along with exercises supported by hints and solutions directly inside IntelliJ IDEA!
Sockets and Pipes
Type ClassesSockets and Pipes is not an introduction to Haskell; it is an introduction to writing software in Haskell. Using a handful of everyday Haskell libraries, this book walks through reading the HTTP specification and implementing it to create a web server.
Introducing EventStorming
Alberto BrandoliniThe deepest tutorial and explanation about EventStorming, straight from the inventor.
node-opcua by example
Etienne RossignonGet the best out of node-opcua through a set of documented examples by the author himself that will allow you to create stunning OPCUA Servers or Clients.
Ansible for DevOps
Jeff GeerlingAnsible is a simple, but powerful, server and configuration management tool. Learn to use Ansible effectively, whether you manage one server—or thousands.
Functional Design and Architecture
Alexander GraninSoftware Design in Functional Programming, Design Patterns and Practices, Methodologies and Application Architectures. How to build real software in Haskell with less efforts and low risks. The first complete source of knowledge.
Composing Software
Eric ElliottAll software design is composition: the act of breaking complex problems down into smaller problems and composing those solutions. Most developers have a limited understanding of compositional techniques. It's time for that to change.
Top Bundles
- #1
Software Architecture for Developers: Volumes 1 & 2 - Technical leadership and communication
2 Books
"Software Architecture for Developers" is a practical and pragmatic guide to modern, lightweight software architecture, specifically aimed at developers. You'll learn:The essence of software architecture.Why the software architecture role should include coding, coaching and collaboration.The things that you really need to think about before... - #2
All the Books of The Medical Futurist
6 Books
We put together the most popular books from The Medical Futurist to provide a clear picture about the major trends shaping the future of medicine and healthcare. Digital health technologies, artificial intelligence, the future of 20 medical specialties, big pharma, data privacy, digital health investments and how technology giants such as Amazon... - #3
PowerShell
3 Books
Buy every PowerShell book from Adam Bertram at a 20% discount! - #4
Cisco CCNA 200-301 Complet
4 Books
Ce lot comprend les quatre volumes du guide préparation à l'examen de certification Cisco CCNA 200-301. - #5
Linux Administration Complet
4 Books
Ce lot comprend les quatre volumes du Guide Linux Administration :Linux Administration, Volume 1, Administration fondamentale : Guide pratique de préparation aux examens de certification LPIC 1, Linux Essentials, RHCSA et LFCS. Administration fondamentale. Introduction à Linux. Le Shell. Traitement du texte. Arborescence de fichiers. Sécurité... - #6
Modern C++ by Nicolai Josuttis
2 Books
- #7
Django for Beginners/APIs/Professionals
3 Books
- #8
Learn Git, Bash, and Terraform the Hard Way
3 Books
Learn Git, Bash and Terraform using the Hard Way method.These technologies are essential tools in the DevOps armoury. These books walk you through their features and subtleties in a simple, gradual way that reinforces learning rather than baffling you with theory. - #9
Software Architecture and Beautiful APIs
2 Books
There is no better way to learn how to design good APIs than to look at many existing examples, complementing the Software Architecture theory on API design. - #10
Digital Future of Healthcare and Pharma
3 Books
These three popular e-books from The Medical Futurist describes how digital health technologies will shape the future of health, healthcare, medicine and pharma with exciting infographics in a digestible format.