As designed Invalid return type of UserUpgrade entity

truonglv

Well-known member
Affected version
2.3.0 beta 6
PHP:
protected function setupApiResultData(EntityResult $result, $verbosity = self::VERBOSITY_NORMAL, array $options = []): void
{
   $result->cost_phrase = $this->cost_phrase;
}

Should not have :void in the end of function.
 
It's the correct return type.

I assume you feel it's invalid because the parent method doesn't have a return type. This is a reasonable assumption, but not actually correct. Extended methods can add a return type to a method which doesn't already have one. It can't change a return type where one is already defined.

This is a new method we've added so it is reasonable to add the correct return type where we can. The parent method was implemented before we were using a modern enough PHP version to support return types, hence why it doesn't have one. We can't add a return type to the original method as that would then break all existing methods which extend it.
 
@Chris D I know it correctly return type but compare with others entity it does not have return type and that has one so it broken for other extends for it.
 
As Chris said, the only reason other entities don't have it is because they were added in previous versions where our minimum version of PHP did not support the void return type, and we can't add it now without breaking backwards-compatibility. I understand it's not consistent but it's better to add type hints where we can than have none at all.
 
Top Bottom