Consider the following code implementing the PHP 8.5 closure in constant expression feature in combination with an attribute.
<?php
declare(strict_types=1);
namespace Demo;
use Attribute;
use Closure;
#[Attribute]
class DemoAttribute
{
public function __construct(Closure $run)
{
}
}
class DemoClass
{
public function __construct(
#[DemoAttribute(run: static function (bool $closureParam): bool {
return $closureParam;
})]
bool $param
)
{
}
}
The SlevomatCodingStandard.TypeHints.ParameterTypeHint falsely detects $closureParam as method parameter and reports a missing type hint.
20 | ERROR | Method \Demo\DemoClass::__construct() does not have parameter
| | type hint nor @param annotation for its parameter $closureParam.
| | (SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingAnyTypeHint)
Consider the following code implementing the PHP 8.5 closure in constant expression feature in combination with an attribute.
The
SlevomatCodingStandard.TypeHints.ParameterTypeHintfalsely detects$closureParamas method parameter and reports a missing type hint.