php version guide
PHP 8.2 Changes
PHP 8.2 added readonly classes, #[\SensitiveParameter], disjunctive normal form types, standalone true, false, and null types, and the Random extension. Dynamic properties became deprecated for most classes.
Changes Worth Recognising
- Readonly classes apply readonly behaviour to every declared instance property.
#[\SensitiveParameter]redacts marked arguments from backtraces.- Dynamic properties are usually a typo or an old object-shaping pattern; declare properties deliberately.
- The Random extension separates engines from randomisers for clearer random-value generation.
Representative Code
PHP example
<?php
readonly class ApiCredentials
{
public function __construct(
public string $clientId,
public string $secret,
) {}
}
$credentials = new ApiCredentials('demo', 'redacted');
echo $credentials->clientId . PHP_EOL;
// Prints:
// demo
Upgrade Review
- Search deprecation logs for dynamic-property writes.
- Use
#[\AllowDynamicProperties]only as a deliberate transitional measure. - Mark secrets at callable boundaries where backtraces could expose them.
The dynamic-property deprecation is the main upgrade audit item for older application code and hydrated objects.
Practice
Remove a Dynamic Property
Write a small class where code assigns an undeclared $email property. Replace the dynamic property with a declared typed property and explain whether it should be nullable.
Show solution
Declare the property explicitly, for example public ?string $email = null; only if missing email is a valid state. Otherwise require it in the constructor.