The \MediaWikiServicesTest::provideGetService() PHPUnit data provider
method uses the ReflectionType::__toString() method to obtain the
return type of service instantiator callables as a string.
In PHP 7.4, calling this method generates an E_DEPRECATED notice.
The solution is to use ReflectionType::getName() instead, available
since PHP 7.1.[1]
This patch updates the method to use ReflectionType::getName()
if it is available, and fall back to ReflectionType::__toString()
otherwise.
---
[1] https://github.com/php/php-src/blob/php-7.4.0RC1/UPGRADING#L395
Bug: T233012
Change-Id: I69b97f75795e6c4e005bf1a23fb798f7e52da2fd
throw new MWException( 'All service callbacks must have a return type defined, ' .
"none found for $name" );
}
- $ret[$name] = [ $name, $fun->getReturnType()->__toString() ];
+
+ $returnType = $fun->getReturnType();
+
+ // ReflectionType::__toString() generates deprecation notices in PHP 7.4 and above
+ // TODO: T228342 - remove this check after MediaWiki only supports PHP 7.1+
+ if ( is_callable( [ $returnType, 'getName' ] ) ) {
+ $ret[$name] = [ $name, $returnType->getName() ];
+ } else {
+ $ret[$name] = [ $name, $fun->getReturnType()->__toString() ];
+ }
}
return $ret;
}