1.2.871. Nullable With Constant

Arguments are automatically nullable with a literal null. They used to also be nullable with a constant null, before PHP 8.0.

<?php

// Extracted from https://github.com/php/php-src/blob/master/UPGRADING

// Replace
function test(int $arg = CONST_RESOLVING_TO_NULL) {}
// With
function test(?int $arg = CONST_RESOLVING_TO_NULL) {}
// Or
function test(int $arg = null) {}

?>

1.2.871.1. Connex PHP features

1.2.871.1.1. Suggestions

  • Use the valid syntax

1.2.871.1.2. Specs

Short name

Functions/NullableWithConstant

Rulesets

All, CE, Changed Behavior, CompatibilityPHP80

Exakat since

2.1.9

PHP Version

With PHP 8.2 and older

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

High

Available in

Entreprise Edition, Community Edition, Exakat Cloud