PHP 8.4 deprecation: implicit nullable parameter types
Problem/Motivation
PHP 8.4 deprecates implicitly nullable parameter types. When a typed parameter
has a default value of NULL without an explicit ? prefix on the type hint,
PHP 8.4 emits a deprecation warning like:
Implicitly marking parameter $foo as nullable is deprecated, the explicit
nullable type (?) must be used instead.
The following signatures across behat-contexts are affected:
src/Behat/Context/EntityContext.php (L116)
protected function visitEntityPath(string $entity_type, $entity, string $subpath = NULL, $language = NULL)
src/Behat/Cores/CoreInterface.php (L54, L401)
public function staticEntityCacheClear($entity_type_id, array $ids = NULL);
public function buildPath(string $path, string $langcode = NULL);
src/Behat/Cores/Drupal7.php (L41, L391)
public function staticEntityCacheClear($entity_type_id, array $ids = NULL)
public function buildPath(string $path, string $langcode = NULL)
src/Behat/Cores/Drupal8.php (L73, L586)
public function staticEntityCacheClear($entity_type_id, array $ids = NULL)
public function buildPath(string $path, string $langcode = NULL)
Steps to reproduce
- Run a Behat test suite with PHP 8.4.
- Trigger any code path that invokes one of the affected methods without
passing the nullable argument (i.e. relying on the NULL default).
- Observe PHP 8.4 deprecation notices for each affected signature.
Proposed resolution
Add an explicit ? nullable marker to each affected typed parameter.
// EntityContext.php — before:
protected function visitEntityPath(string $entity_type, $entity, string $subpath = NULL, $language = NULL)
// after:
protected function visitEntityPath(string $entity_type, $entity, ?string $subpath = NULL, $language = NULL)
// CoreInterface.php + Drupal7.php + Drupal8.php — before:
public function staticEntityCacheClear($entity_type_id, array $ids = NULL);
public function buildPath(string $path, string $langcode = NULL);
// after:
public function staticEntityCacheClear($entity_type_id, ?array $ids = NULL);
public function buildPath(string $path, ?string $langcode = NULL);
The implementations and callers are unaffected: any caller already passing
NULL or omitting the argument will continue to work identically.
Remaining tasks
- Apply the patch.
- Confirm no PHP 8.4 deprecation notices are emitted for the affected methods.
User interface changes
None.
API changes
The signatures of the following methods change from implicitly nullable to
explicitly nullable typed parameters. Callers that already pass NULL or omit
the argument are unaffected:
- EntityContext::visitEntityPath() — string $subpath
- CoreInterface::staticEntityCacheClear() / Drupal7 / Drupal8 — array $ids
- CoreInterface::buildPath() / Drupal7 / Drupal8 — string $langcode
PHP 8.4 deprecation: implicit nullable parameter types
Problem/Motivation
PHP 8.4 deprecates implicitly nullable parameter types. When a typed parameter
has a default value of
NULLwithout an explicit?prefix on the type hint,PHP 8.4 emits a deprecation warning like:
The following signatures across
behat-contextsare affected:Steps to reproduce
passing the nullable argument (i.e. relying on the NULL default).
Proposed resolution
Add an explicit ? nullable marker to each affected typed parameter.
// EntityContext.php — before:
protected function visitEntityPath(string $entity_type, $entity, string $subpath = NULL, $language = NULL)
// after:
protected function visitEntityPath(string $entity_type, $entity, ?string $subpath = NULL, $language = NULL)
// CoreInterface.php + Drupal7.php + Drupal8.php — before:
public function staticEntityCacheClear($entity_type_id, array $ids = NULL);
public function buildPath(string $path, string $langcode = NULL);
// after:
public function staticEntityCacheClear($entity_type_id, ?array $ids = NULL);
public function buildPath(string $path, ?string $langcode = NULL);
The implementations and callers are unaffected: any caller already passing
NULL or omitting the argument will continue to work identically.
Remaining tasks
User interface changes
None.
API changes
The signatures of the following methods change from implicitly nullable to
explicitly nullable typed parameters. Callers that already pass NULL or omit
the argument are unaffected: