Skip to content

Commit

Permalink
[TASK] Avoid php deprecation in FrameworkState
Browse files Browse the repository at this point in the history
With PHP8.3 the `ReflectionProperty->setValue()` method
emits a E_DEPRECATED if a value should be set to a class
and the context is not set as first argument.

For instanciated classes the class needs to be provided,
which is not possible for a static class or property.

The solution for this is to use `null` as first argument
as context object. That avoids the deprecation and keeps
the backward compatibility.

The testing-framework provides a tool to keep and handle
static Framework state, which uses reflection under the
hood and therefore needs the null context for `setValue()`.

Releases: main, 7, 6
  • Loading branch information
sbuerk committed Aug 2, 2023
1 parent 375223d commit 73fca80
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Classes/Core/Functional/Framework/FrameworkState.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static function reset()
$generalUtilityReflection = new \ReflectionClass(GeneralUtility::class);
$generalUtilityIndpEnvCache = $generalUtilityReflection->getProperty('indpEnvCache');
$generalUtilityIndpEnvCache->setAccessible(true);
$generalUtilityIndpEnvCache->setValue([]);
$generalUtilityIndpEnvCache->setValue(null, []);

GeneralUtility::resetSingletonInstances([]);

Expand Down Expand Up @@ -126,19 +126,19 @@ public static function pop()
$generalUtilityReflection = new \ReflectionClass(GeneralUtility::class);
$generalUtilityIndpEnvCache = $generalUtilityReflection->getProperty('indpEnvCache');
$generalUtilityIndpEnvCache->setAccessible(true);
$generalUtilityIndpEnvCache->setValue($state['generalUtilityIndpEnvCache']);
$generalUtilityIndpEnvCache->setValue(null, $state['generalUtilityIndpEnvCache']);

GeneralUtility::resetSingletonInstances($state['generalUtilitySingletonInstances']);

$rootlineUtilityReflection = new \ReflectionClass(RootlineUtility::class);
$rootlineUtilityLocalCache = $rootlineUtilityReflection->getProperty('localCache');
$rootlineUtilityLocalCache->setAccessible(true);
$rootlineUtilityLocalCache->setValue($state['rootlineUtilityLocalCache']);
$rootlineUtilityLocalCache->setValue(null, $state['rootlineUtilityLocalCache']);
$rootlineUtilityRootlineFields = $rootlineUtilityReflection->getProperty('rootlineFields');
$rootlineUtilityRootlineFields->setAccessible(true);
$rootlineUtilityRootlineFields->setValue($state['rootlineUtilityRootlineFields']);
$rootlineUtilityRootlineFields->setValue(null, $state['rootlineUtilityRootlineFields']);
$rootlineUtilityPageRecordCache = $rootlineUtilityReflection->getProperty('pageRecordCache');
$rootlineUtilityPageRecordCache->setAccessible(true);
$rootlineUtilityPageRecordCache->setValue($state['rootlineUtilityPageRecordCache']);
$rootlineUtilityPageRecordCache->setValue(null, $state['rootlineUtilityPageRecordCache']);
}
}

0 comments on commit 73fca80

Please sign in to comment.