PHP 8.3 Features for WordPress Plugin Development

PHP 8.3 for WordPress plugin developers

PHP 8.3 (November 2023) is a release of small, practical changes: typed class constants, an #[\Override] attribute, json_validate(), dynamic access to class constants and a few deprecations. In mid-2025 it is the version many hosts recommend, so plugins can start to require it, or at least must run on it without notices.

Problem: A plugin should move its minimum to PHP 8.3. The team wants to know which new features are worth using and which changes can produce warnings on sites that already run 8.3.

Solution: Use typed class constants and #[\Override] in the plugin’s class hierarchy, json_validate() for large incoming JSON, check the deprecations (get_class() and get_parent_class() without arguments, range() edge cases) with WP_DEBUG on, and set Requires PHP: 8.3 in the plugin header.

Typed class constants

interface Ha_Gateway {
    const string ID = '';
}

final class Ha_Gateway_Invoice implements Ha_Gateway {
    const string ID = 'ha_invoice';
    const int MAX_DAYS = 30;
}

Constants can now have a type, and a subclass or implementing class must keep it: const int ID = 5; in a class that implements Ha_Gateway is a fatal error at compile time. For plugins with base classes and many implementations (gateways, integrations, field types), this catches mistakes that used to show up only at runtime.

#[\Override]

class Ha_Settings_Page extends Ha_Admin_Page {
    #[\Override]
    protected function render_fields(): void {
        // ...
    }
}

The attribute says “this method overrides a parent method”. If the parent method is renamed or removed later, PHP throws a fatal error instead of silently keeping a method that is never called. Very useful when extending WordPress classes like WP_List_Table or WP_REST_Controller, whose method names must match exactly.

json_validate()

$body = $request->get_body();
if ( ! json_validate( $body ) ) {
    return new WP_Error( 'ha_invalid_json', __( 'Invalid JSON.', 'textdomain' ), array( 'status' => 400 ) );
}
$data = json_decode( $body, true );

json_validate() checks the syntax without building the PHP arrays, which uses much less memory for large payloads. If the data is decoded afterwards anyway, json_decode() with a null check is enough; the function pays off when invalid input should be rejected early, for example in a webhook receiver.

Dynamic class constant fetch

$level = 'MAX_DAYS';
echo Ha_Gateway_Invoice::{$level}; // 30, before 8.3: constant( Ha_Gateway_Invoice::class . '::' . $level )

What can produce notices on PHP 8.3

  • get_class() and get_parent_class() without arguments are deprecated; use static::class, self::class or get_class( $this ).
  • range() throws on some odd inputs it used to accept (empty strings, float steps that do not fit); check helper code that builds ranges from user input.
  • Changes in unserialize() warnings: trailing data after a valid serialized value now emits a warning. Options and meta that were saved by hand with broken serialization show up here.
  • Dynamic properties have been deprecated since 8.2 and still emit notices: PHP 8.2 in WordPress plugins.

Run the plugin’s tests on 8.3, click through the admin with WP_DEBUG and WP_DEBUG_LOG on, and check debug.log. Static analysis finds many of these issues before runtime: PHPStan for WordPress plugins.

Requiring PHP 8.3

/**
 * Plugin Name: HA Invoices
 * Requires at least: 6.6
 * Requires PHP: 8.3
 */

Typed constants and attributes in function signatures are syntax that older PHP versions cannot parse; with the header, WordPress refuses activation on older PHP with a message instead of a parse error. Check how many of your users already run 8.3 (WordPress.org shows PHP version statistics for the whole ecosystem) before raising the minimum.

NOTE: #[\Override] is only an attribute: on PHP 8.0–8.2 it is parsed and ignored, so it can be added to code that still supports older versions. Typed constants cannot; they need 8.3. WordPress core itself runs on PHP 8.3 and is tested on it, but full compatibility of a site is decided by its plugins.