phptools-docs
phptools-docs copied to clipboard
Checking `Override` attribute error `PHP2437` with overlay traits
Here is the code:
trait A
{
abstract protected static function T();
}
trait B
{
use A
#[Override]
protected static function T()
{
echo 'T';
}
}
class TT
{
use B;
}
The code works, however PHPTools displays an error message: 'B::T has #[Override] attribute, but no matching parent method exists (PHP2437)' in class TT.
Thank you for the test case.
We'll try to fix that.
Just for a matter of interest - isn't it technically correct? class TT does not have a parent
Thank you for the test case.
We'll try to fix that.
Just for a matter of interest - isn't it technically correct?
class TTdoes not have a parent
I just simplified the code. The parent class of class TT shows the same error.:
abstract class T
{
}
trait A
{
abstract protected static function T();
}
trait B
{
use A
#[Override]
protected static function T()
{
echo 'T';
}
}
class TT extends T
{
use B;
}
Another issue with __construct:
abstract class T
{
public function __construct() {}
}
class TT extends T
{
#[Override]
public function __construct() {}
}
You have the same error PHP2437 for this use case.
@jakubmisek I added another related use case with __construct.
@Renji-FR __construct() method does not satisfy #[/Override] as specified by wiki.php.net/rfc/marking_overriden_methods , section Semantics
__construct() of a parent class do not satisfy #[\Override], because it's not part of the API of an already-constructed object.
@zengbo, according to wiki.php.net/rfc/marking_overriden_methods#semantics:
the #[\Override] attribute on a trait method requires the existence of a matching method in a parent class or implemented interface.
So the PHP2437 error should be correct here.