Skip to content

What’s New in PHP 8.6

Work through the PHP 8.6 release announcement one topic at a time. Each chapter demonstrates a language feature, library addition, performance change, or migration in a small PHP script.

Start by building callbacks, modeling timeouts, and checking property access. The extension labs use PHP to work with URLs, archives, Unicode text, and local TLS connections.

If you’re preparing an upgrade from PHP 8.5, go straight to the deprecations and compatibility chapters. You’ll see what to change and how to verify the resulting behavior.

This series is for developers who already use PHP or are comfortable with functions, arrays, and classes. If you’re new to the language, start with PHP Basics.

  • A PHP 8.6 CLI. The examples use PHP 8.6.0 behavior. PHP downloads
  • A local checkout of Code with PHP and a terminal opened at its root.
  • Optional extensions and services listed in the chapters that use them. The MySQLi labs need a database connection, and the TLS labs run on loopback.
  • Allow about 10–15 minutes per chapter.

You’ll assemble a set of small programs for common jobs such as bounding inputs, processing incoming stream data, formatting text, and checking upgrade behavior. The PHP source is in the series example directory.

  • Use the new syntax and core APIs in standalone scripts.
  • Check which extensions and external libraries your PHP build supplies.
  • Recognize several operations whose results, warnings, or exceptions change after upgrading.
  • Verify your migration with focused inputs and expected output.

Choose a chapter and run its example. Compare the output, then try the exercise to see how changing an input or configuration affects the result. The chapters work independently unless a prerequisite says otherwise.

For a first pass, follow the four groups in order: language and core APIs → extensions and protocols → performance → upgrade changes.

Run these commands from the repository root.

Terminal window
# Confirm which PHP binary you are using.
php --version
# Run the first lesson.
php code/php-8-6/01-partial-function-application/partial-function-application.php

The first two lines from the example are:

INFO [worker] Job started
ERROR [billing] Payment declined
  1. Partial Function Application
  2. Elapsed Time with Time\Duration
  3. Wait for I/O with Io\Poll
  4. Structured Stream Errors
  5. Limit Values with clamp()
  6. Type-Safe Sorting with SortDirection
  7. DocComments on Function Parameters
  8. Inspect Property Read and Write Access
  9. Default Values for Readonly Properties
  10. Override Attributes on Constants and Enum Cases
  11. Customize Enum Dumps with __debugInfo()
  12. Change Properties on Objects Held in Constants
  1. Build URLs and URI References from Components
  2. Identify URI and Host Types
  3. Percent-Encode WHATWG URL Components
  4. Establish a Shared Key with X-Wing and ML-KEM-768
  5. Encrypt IP Addresses with Sodium
  6. Extend Hash Output with SHAKE and TurboSHAKE
  7. Resume a TLS Stream Session
  8. Authenticate TLS Streams with External PSKs
  9. Send TLS 1.3 Early Data
  10. Quote SQL String Literals with MySQLi
  11. Set Byte Order with pack() and unpack()
  12. Locate a JSON Syntax Error
  13. Show Function Arguments in PHP Errors
  14. Reverse Text by Grapheme Cluster
  15. Format Localized Number Ranges
  16. Read and Write ZIP Archives in Memory
  1. Compiler Optimizations for array_map()
  2. Faster printf() with Simple Formats
  3. Caching Stateless Closures
  4. Benchmark JSON Encoding on Your Data
  1. Move Returns Out of finally Blocks
  2. Move Results and Generators Out of Object Lifecycles
  3. Return an Array from __debugInfo()
  4. Rename Deprecated Identifiers
  5. Migrate mbstring Regular Expressions to PCRE
  6. Replace Deprecated Numeric Aliases
  7. Replace spl_object_hash() and spl_classes()
  8. Pass Arrays to Array and Compression APIs
  9. Replace strcoll() and SORT_LOCALE_STRING with Collator
  10. Drop the Third Argument to define()
  11. Handle Class Names Explicitly in Type Checks
  12. Set a Limit for php://filter Chains
  13. Audit PHP 8.6 Session Cookie Defaults
  14. Validate IDs in Custom Session Handlers
  15. Move Phonetic Matching Out of Core
  16. Replace Deprecated MySQLi Charset and Statement Calls
  17. Migrate SplFileObject CSV Calls
  18. Replace Deprecated ArrayIterator Methods
  19. Account for Form Feeds in trim()
  20. Handle Stream Flush and Close Failures
  21. Handle New ValueErrors When Upgrading

Use 8.6 for the examples. Several migration scripts also run on 8.5, which lets you compare behavior. PHP 8.5 cannot parse the new partial-application syntax.

The chapters cover the features, improvements, and upgrade notes highlighted in the release announcement. For changes specific to other extensions, SAPIs, or platforms, consult the migration guide and versioned upgrade notes.

Check php --version and use php -m to list your extensions. If you report a problem, include the chapter number, PHP version, OS, and the output from the example. Code with PHP issues