What’s New in PHP 8.6
Overview
Section titled “Overview”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.
Who This Is For
Section titled “Who This Is For”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.
Prerequisites
Section titled “Prerequisites”- 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.
What You’ll Build
Section titled “What You’ll Build”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.
Learning Objectives
Section titled “Learning Objectives”- 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.
How This Series Works
Section titled “How This Series Works”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.
Quick Start
Section titled “Quick Start”Run these commands from the repository root.
# 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.phpThe first two lines from the example are:
INFO [worker] Job startedERROR [billing] Payment declinedChapters
Section titled “Chapters”Language and core APIs
Section titled “Language and core APIs”- Partial Function Application
- Elapsed Time with Time\Duration
- Wait for I/O with Io\Poll
- Structured Stream Errors
- Limit Values with clamp()
- Type-Safe Sorting with SortDirection
- DocComments on Function Parameters
- Inspect Property Read and Write Access
- Default Values for Readonly Properties
- Override Attributes on Constants and Enum Cases
- Customize Enum Dumps with __debugInfo()
- Change Properties on Objects Held in Constants
Extensions and protocols
Section titled “Extensions and protocols”- Build URLs and URI References from Components
- Identify URI and Host Types
- Percent-Encode WHATWG URL Components
- Establish a Shared Key with X-Wing and ML-KEM-768
- Encrypt IP Addresses with Sodium
- Extend Hash Output with SHAKE and TurboSHAKE
- Resume a TLS Stream Session
- Authenticate TLS Streams with External PSKs
- Send TLS 1.3 Early Data
- Quote SQL String Literals with MySQLi
- Set Byte Order with pack() and unpack()
- Locate a JSON Syntax Error
- Show Function Arguments in PHP Errors
- Reverse Text by Grapheme Cluster
- Format Localized Number Ranges
- Read and Write ZIP Archives in Memory
Performance
Section titled “Performance”- Compiler Optimizations for array_map()
- Faster printf() with Simple Formats
- Caching Stateless Closures
- Benchmark JSON Encoding on Your Data
Deprecations and upgrade changes
Section titled “Deprecations and upgrade changes”- Move Returns Out of finally Blocks
- Move Results and Generators Out of Object Lifecycles
- Return an Array from __debugInfo()
- Rename Deprecated Identifiers
- Migrate mbstring Regular Expressions to PCRE
- Replace Deprecated Numeric Aliases
- Replace spl_object_hash() and spl_classes()
- Pass Arrays to Array and Compression APIs
- Replace strcoll() and SORT_LOCALE_STRING with Collator
- Drop the Third Argument to define()
- Handle Class Names Explicitly in Type Checks
- Set a Limit for php://filter Chains
- Audit PHP 8.6 Session Cookie Defaults
- Validate IDs in Custom Session Handlers
- Move Phonetic Matching Out of Core
- Replace Deprecated MySQLi Charset and Statement Calls
- Migrate SplFileObject CSV Calls
- Replace Deprecated ArrayIterator Methods
- Account for Form Feeds in trim()
- Handle Stream Flush and Close Failures
- Handle New ValueErrors When Upgrading
Frequently Asked Questions
Section titled “Frequently Asked Questions”Can I follow the series on PHP 8.5?
Section titled “Can I follow the series on PHP 8.5?”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.
Does this cover the whole changelog?
Section titled “Does this cover the whole changelog?”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.
Getting Help
Section titled “Getting Help”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