Skip to content

Commit

Permalink
[BUGFIX] Remove deprecated reflection API usage
Browse files Browse the repository at this point in the history
PHP 8 deprecated a number of very old bits of the Reflection API. This
patch updates ClassSchema to use the newer equivalents.

Also fixes some unrelated PHP 8.0 errors around undefined value handling.

Resolves: #94001
Releases: master, 10.4
Change-Id: Id235fa830894e9a2dc6465444ec2c6808f18c3aa
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/68994
Tested-by: core-ci <typo3@b13.com>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Benni Mack <benni@typo3.org>
  • Loading branch information
Crell authored and bmack committed May 4, 2021
1 parent 07c761c commit 58e4ceb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
6 changes: 3 additions & 3 deletions typo3/sysext/core/Classes/DataHandling/DataHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4653,7 +4653,7 @@ protected function inlineLocalizeSynchronize($table, $id, $command)
$field = $command['field'];
$language = $command['language'];
$action = $command['action'];
$ids = $command['ids'];
$ids = $command['ids'] ?? [];

if (!$field || !($action === 'localize' || $action === 'synchronize') && empty($ids) || !isset($GLOBALS['TCA'][$table]['columns'][$field]['config'])) {
return;
Expand Down Expand Up @@ -5991,7 +5991,7 @@ public function remapListedDBRecords()
foreach ($this->registerDBList as $table => $records) {
foreach ($records as $uid => $fields) {
$newData = [];
$theUidToUpdate = $this->copyMappingArray_merged[$table][$uid];
$theUidToUpdate = $this->copyMappingArray_merged[$table][$uid] ?? null;
$theUidToUpdate_saveTo = BackendUtility::wsMapId($table, $theUidToUpdate);
foreach ($fields as $fieldName => $value) {
$conf = $GLOBALS['TCA'][$table]['columns'][$fieldName]['config'];
Expand Down Expand Up @@ -6151,7 +6151,7 @@ public function remapListedDBRecords_procDBRefs($conf, $value, $MM_localUid, $ta
*/
public function remapListedDBRecords_procInline($conf, $value, $uid, $table)
{
$theUidToUpdate = $this->copyMappingArray_merged[$table][$uid];
$theUidToUpdate = $this->copyMappingArray_merged[$table][$uid] ?? null;
if ($conf['foreign_table']) {
$inlineType = $this->getInlineFieldType($conf);
if ($inlineType === 'mm') {
Expand Down
33 changes: 23 additions & 10 deletions typo3/sysext/extbase/Classes/Reflection/ClassSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,12 @@ protected function reflectMethods(\ReflectionClass $reflectionClass): void
return $annotation instanceof IgnoreValidation && $annotation->argumentName === $parameterName;
});

$reflectionType = $reflectionParameter->getType();

$this->methods[$methodName]['params'][$parameterName] = [];
$this->methods[$methodName]['params'][$parameterName]['position'] = $parameterPosition; // compat
$this->methods[$methodName]['params'][$parameterName]['byReference'] = $reflectionParameter->isPassedByReference(); // compat
$this->methods[$methodName]['params'][$parameterName]['array'] = $reflectionParameter->isArray(); // compat
$this->methods[$methodName]['params'][$parameterName]['array'] = false; // compat
$this->methods[$methodName]['params'][$parameterName]['optional'] = $reflectionParameter->isOptional();
$this->methods[$methodName]['params'][$parameterName]['allowsNull'] = $reflectionParameter->allowsNull();
$this->methods[$methodName]['params'][$parameterName]['class'] = null; // compat
Expand All @@ -374,14 +376,25 @@ protected function reflectMethods(\ReflectionClass $reflectionClass): void
$this->methods[$methodName]['params'][$parameterName]['defaultValue'] = $reflectionParameter->getDefaultValue();
}

if (($reflectionType = $reflectionParameter->getType()) instanceof \ReflectionNamedType) {
$this->methods[$methodName]['params'][$parameterName]['type'] = $reflectionType->getName();
// A ReflectionNamedType means "there is a type specified, and it's not a union type."
// (Union types are not handled, currently.)
if ($reflectionType instanceof \ReflectionNamedType) {
$this->methods[$methodName]['params'][$parameterName]['allowsNull'] = $reflectionType->allowsNull();
}

if (($parameterClass = $reflectionParameter->getClass()) instanceof \ReflectionClass) {
$this->methods[$methodName]['params'][$parameterName]['class'] = $parameterClass->getName();
$this->methods[$methodName]['params'][$parameterName]['type'] = ltrim($parameterClass->getName(), '\\');
// A built-in type effectively means "not a class".
if ($reflectionType->isBuiltin()) {
$this->methods[$methodName]['params'][$parameterName]['array'] = $reflectionType->getName() === 'array'; // compat
$this->methods[$methodName]['params'][$parameterName]['type'] = ltrim($reflectionType->getName(), '\\');
} else {
// This is mainly to confirm that the class exists. If it doesn't, a ReflectionException
// will be thrown. It's not the ideal way of doing so, but it maintains the existing API
// so that the exception can get caught and recast to a TYPO3-specific exception.
/** @var class-string<mixed> $classname */
$classname = $reflectionType->getName();
$reflection = new \ReflectionClass($classname);
// There's a single type declaration that is a class.
$this->methods[$methodName]['params'][$parameterName]['class'] = $reflectionType->getName();
$this->methods[$methodName]['params'][$parameterName]['type'] = $reflectionType->getName();
}
}

if ($docComment !== '' && $this->methods[$methodName]['params'][$parameterName]['type'] === null) {
Expand All @@ -408,10 +421,10 @@ protected function reflectMethods(\ReflectionClass $reflectionClass): void
}

// Extbase DI
if ($reflectionParameter->getClass() instanceof \ReflectionClass
if ($reflectionType instanceof \ReflectionNamedType && !$reflectionType->isBuiltin()
&& ($reflectionMethod->isConstructor() || $this->hasInjectMethodName($reflectionMethod))
) {
$this->methods[$methodName]['params'][$parameterName]['dependency'] = $reflectionParameter->getClass()->getName();
$this->methods[$methodName]['params'][$parameterName]['dependency'] = $reflectionType->getName();
}

// Extbase Validation
Expand Down

0 comments on commit 58e4ceb

Please sign in to comment.