Skip to content

PHP 8.4 | Implicitly nullable deprecation ignores null in constant expressions in default value #13752

Closed as not planned
@jrfnl

Description

@jrfnl

Description

The following code:

<?php
define('MY_CONST', false);
function constantExpressionInDefault( int $a = MY_CONST ? 10 : NULL) {}

Resulted in this output:

But I expected this output instead:

Deprecated: Implicitly marking parameter $paramA as nullable is deprecated, the explicit nullable type must be used instead in ... on line 3

Demo:

Context

I was doing some experimenting with the new deprecation as introduced in #12959 for the PHPCompatibility sniff to detect this via static analysis.

Not sure if this behaviour is intentional or a bug, but I figured I should flag it, so you all could have a look at it and take a decision on what should be done with parameters declared like the above example.

/cc @kocsismate @Girgias

PHP Version

master

Operating System

N/A

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions