User Tools

Site Tools


advanced_concepts:new_in_php

3. New in PHP 8.3 / 8.4 — The Evolving Language

PHP 8.3 and 8.4 continue the quiet evolution that began with PHP 8.0:
a language becoming more intentional, more expressive, and more predictable.

These versions don’t introduce dramatic new paradigms.
Instead, they refine the language’s shape
— smoothing edges, tightening contracts,
and making everyday code more “honest”.

They reflect a broader truth:
modern PHP evolves through clarity, not complexity.


1. PHP 8.3 — Refinements That Strengthen the Core

PHP 8.3 focuses on consistency, safety, and expressiveness.
Nothing flashy — but everything meaningful.

a. Typed Class Constants

You can now declare types on class constants:

class Config {
    public const string MODE = 'production';
}

This brings constants into the same world as properties and parameters:
shape is explicit.

b. Deep Cloning of Readonly Properties

Readonly properties can now be deep‑cloned safely:

$copy = clone $object;

This makes readonly objects feel more like true values.

c. New json_validate() Function

A fast way to check if a string is valid JSON:

if (json_validate($payload)) { /* ... */ }

No decoding.
No exceptions.
Just validation.

d. More Precise Type Handling

PHP 8.3 tightens type behavior in subtle ways:

  • better handling of null in certain contexts
  • more consistent error messages
  • improved internal type inference

These changes make the language feel more predictable.


2. PHP 8.4 — A Language Growing Into Itself

PHP 8.4 continues the same theme:
→less noise, more clarity.

a. Property Hooks (Getters/Setters Without Ceremony)

This is the headline feature of 8.4
— a way to define getters and setters directly on properties:

class User {
    public string $name {
        get => $this->name;
        set => $this->name = trim($value);
    }
}

No boilerplate methods.
No magic.
Just explicit behavior.

This is PHP becoming more expressive without becoming more magical.

b. New #[\Override] Attribute

You can now mark methods that intentionally override a parent method:

class Child extends Parent {
    #[\Override]
    public function handle() { /* ... */ }
}

If the parent method doesn’t exist, PHP errors.
This prevents accidental overrides — a common source of bugs.

c. More Improvements to Readonly and Enums

PHP 8.4 continues refining:

  • readonly classes
  • enum usability
  • internal consistency

These are small changes,
but they reinforce the language’s direction.

d. Performance Improvements

PHP 8.4 includes meaningful performance gains, especially in:

  • string handling
  • array operations
  • JIT refinements
  • internal optimizations

Nothing you need to learn — but everything you benefit from.


3. The Mental Model of PHP’s Evolution

PHP 8.3 and 8.4 show a language that is:

  • maturing, not reinventing itself
  • tightening contracts, not adding complexity
  • reducing boilerplate, not hiding behavior
  • clarifying intent, not introducing magic

The key idea:
Modern PHP evolves by making the language more honest.

Every new feature is about reducing ambiguity,
not adding cleverness.


4. When AI Gets This Wrong

AI often:

  • uses 8.4 features in 8.0 codebases
  • mixes property hooks with magic methods
  • invents attributes that don’t exist
  • assumes async/await exists in PHP
  • uses typed constants incorrectly
  • treats #[Override] as optional decoration

Our mental model helps us see when a feature belongs to the language
—and when AI is hallucinating something from another ecosystem.


Summary

PHP 8.3 and 8.4 continue the quiet refinement of the language:

  • typed class constants
  • safer readonly behavior
  • property hooks
  • override validation
  • performance improvements
  • more consistent type behavior

These versions don’t change how we think about PHP
—they make the language more aligned with the way we already think.

They teach us that
modern PHP evolves through clarity, stability, and intention.


advanced_concepts/new_in_php.txt · Last modified: by editor