O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Upgrading to PHP 7

Book Description

PHP 7—the most dramatic update to the language in over a decade—has arrived. This O’Reilly report provides you with a short guide to the major changes in this new release, including a revamped engine (Zend Engine 3), a bunch of new features, and lots of language cleanup. You’ll learn about basic language changes, deprecated features, Unicode enhancements, changes in Object-Oriented programming, and other enhancements.

You’ll also discover why it’s taken more than 10 years for the first new major version of PHP since PHP 5 to appear—and what happened to version 6 in the meantime.

Get important details regarding changes to PHP 7, including:

  • Deprecated features, starting with alternative PHP tags and POSIX-compatible regular expressions
  • Uniform Variable Syntax, including consistency fixes and new syntax
  • Basic language changes, such as new operators, constant arrays, new functions, and regular expressions
  • Expectations and Assertions
  • Error handling
  • Enhancements to PHP’s Unicode, closure, and Generator features
  • Changes in Object-Oriented programming
  • Scalar type hints (perhaps the most polarizing and exciting new feature)

Table of Contents

  1. 1. Upgrading to PHP 7
    1. PHP 7 Timeline
    2. How We Got Here
    3. Release Cycle
  2. 2. Deprecated Features
    1. Alternative PHP Tags
    2. POSIX-Compatible Regular Expressions
      1. Migrating to Perl Compatible Regular Expressions
    3. Multiple Default Cases in Switches
    4. Removal of the Original MySQL Extension
      1. Migrating to Procedural mysqli
      2. Migrating to an Object-Oriented API
      3. Using Mysqli
    5. Summary
  3. 3. Uniform Variable Syntax
    1. Consistency Fixes
    2. New Syntax
      1. New Combinations
      2. Nested double colons
      3. Nested Method and Function Calls
      4. Arbitrary Expression Dereferencing
    3. Dereferencing scalars
    4. Future Syntax
    5. Backward Compatibility Issues
    6. Summary
  4. 4. Basic Language Changes
    1. Operators
      1. Null Coalesce Operator
      2. Combined Comparison Operator
    2. Constant Arrays
    3. Unpacking Objects Using list()
    4. New Functions
      1. Integer Division
    5. Regular Expressions
    6. Cryptographically Secure Values
    7. Function Changes
      1. Sessions
    8. Filtered unserialize()
    9. Move Up Multiple Levels with dirname()
    10. Salts Deprecated in password_hash()
    11. Summary
  5. 5. Expectations and Assertions
    1. Expectations
    2. Summary
  6. 6. Error Handling
    1. Exceptions on Constructor Failure
    2. Engine Exceptions
      1. Exception Hierarchy
    3. Error Exceptions
      1. \Error
      2. \AssertionError
      3. \ArithmeticError and \DivisionByZeroError
      4. \ParseError
      5. \TypeError
    4. Catchable Fatal Errors
    5. \Throwable and Userland
    6. Calling Methods on non-objects
    7. Summary
  7. 7. Unicode Enhancements
    1. Unicode Codepoint Escape Syntax
    2. New Internationalization Features
    3. Working with Unicode Characters
    4. Summary
  8. 8. Closure Enhancements
    1. Bind Closure On Call
    2. Summary
  9. 9. Generator Enhancements
    1. Generator Return Values
    2. Generator Delegation
    3. Summary
  10. 10. Changes in Object-Oriented Programming
    1. Context-Sensitive Lexer
    2. PHP 4 Constructors Deprecated
    3. Group Use Declarations
    4. Anonymous Classes
    5. Anonymous Class Names
    6. Summary
  11. 11. Type Hints
    1. Scalar Type Hints
      1. Coercive Types
      2. Precision Loss
      3. Strict Types
    2. Return Type Hints
    3. Reserved Keywords for Future Types
    4. Summary
  12. A. Resources
    1. Further Reading
    2. Other Resources
  13. B. RFCs for PHP 7.0
    1. Deprecated Features
    2. Uniform Variable Syntax
    3. Basic Language Changes
      1. Other RFCs
    4. Expectations and Assertions
    5. Error Handling
      1. Other RFCs
    6. Unicode Enhancements
    7. Closures
    8. Generators
    9. Object-Oriented Programming
    10. Type Hints
    11. Internals Changes