PHP

PHP

By DeepSource

Use of nullable `mixed` is forbiddenPHP-T1006

Type check

The mixed type already includes null, so specifying mixed type as a nullable is redundant and doesn't make any sense. PHP lets you typehint properties, parameters, and return values as mixed which can contain any value.

To fix this issue, it is recommended to drop null from the nullable mixed type.

Examples

Bad practice

class ErrorHandler
{
    // invalid: mixed already includes null
    private ?mixed $lastFatalTrace = null;
}

Recommended

class ErrorHandler
{
    private mixed $lastFatalTrace = null;
}

References