diff --git a/typo3/sysext/core/Classes/FormProtection/FormProtectionFactory.php b/typo3/sysext/core/Classes/FormProtection/FormProtectionFactory.php index 3388c01660367850e3cda719b47faaea0a245dc9..203c98b213040986fee7e6d45cbd97b3fea56714 100644 --- a/typo3/sysext/core/Classes/FormProtection/FormProtectionFactory.php +++ b/typo3/sysext/core/Classes/FormProtection/FormProtectionFactory.php @@ -67,19 +67,20 @@ class FormProtectionFactory * @param string $classNameOrType Name of a form protection class, or one * of the pre-defined form protection types: * frontend, backend, installtool + * @param mixed $constructorArguments Arguments for the class-constructor * @return \TYPO3\CMS\Core\FormProtection\AbstractFormProtection the requested instance */ - public static function get($classNameOrType = 'default') + public static function get($classNameOrType = 'default', ...$constructorArguments) { if (isset(self::$instances[$classNameOrType])) { return self::$instances[$classNameOrType]; } if ($classNameOrType === 'default' || $classNameOrType === 'installtool' || $classNameOrType === 'frontend' || $classNameOrType === 'backend') { $classNameAndConstructorArguments = self::getClassNameAndConstructorArgumentsByType($classNameOrType); + self::$instances[$classNameOrType] = self::createInstance(...$classNameAndConstructorArguments); } else { - $classNameAndConstructorArguments = func_get_args(); + self::$instances[$classNameOrType] = self::createInstance($classNameOrType, ...$constructorArguments); } - self::$instances[$classNameOrType] = self::createInstance($classNameAndConstructorArguments); return self::$instances[$classNameOrType]; } @@ -177,17 +178,17 @@ class FormProtectionFactory * Creates an instance for the requested class $className * and stores it internally. * - * @param array $classNameAndConstructorArguments + * @param array $className + * @param mixed $constructorArguments * @throws \InvalidArgumentException * @return AbstractFormProtection */ - protected static function createInstance(array $classNameAndConstructorArguments) + protected static function createInstance($className, ...$constructorArguments) { - $className = $classNameAndConstructorArguments[0]; if (!class_exists($className)) { throw new \InvalidArgumentException('$className must be the name of an existing class, but ' . 'actually was "' . $className . '".', 1285352962); } - $instance = call_user_func_array([GeneralUtility::class, 'makeInstance'], $classNameAndConstructorArguments); + $instance = GeneralUtility::makeInstance($className, ...$constructorArguments); if (!$instance instanceof AbstractFormProtection) { throw new \InvalidArgumentException('$className must be a subclass of ' . AbstractFormProtection::class . ', but actually was "' . $className . '".', 1285353026); } diff --git a/typo3/sysext/core/Classes/Utility/GeneralUtility.php b/typo3/sysext/core/Classes/Utility/GeneralUtility.php index 23a4b7d08453bf84317afeb4f724cf9fd9bd860b..c0b6bcda415ab76649af5f1c021944b4e3c1fc7a 100755 --- a/typo3/sysext/core/Classes/Utility/GeneralUtility.php +++ b/typo3/sysext/core/Classes/Utility/GeneralUtility.php @@ -3982,12 +3982,11 @@ class GeneralUtility * the instance of a specific class. * * @param string $className name of the class to instantiate, must not be empty and not start with a backslash - * + * @param mixed $constructorArguments Arguments for the constructor * @return object the created instance - * * @throws \InvalidArgumentException if $className is empty or starts with a backslash */ - public static function makeInstance($className) + public static function makeInstance($className, ...$constructorArguments) { if (!is_string($className) || empty($className)) { throw new \InvalidArgumentException('$className must be a non empty string.', 1288965219); @@ -4016,7 +4015,7 @@ class GeneralUtility return array_shift(self::$nonSingletonInstances[$finalClassName]); } // Create new instance and call constructor with parameters - $instance = static::instantiateClass($finalClassName, func_get_args()); + $instance = new $finalClassName(...$constructorArguments); // Register new singleton instance if ($instance instanceof SingletonInterface) { self::$singletonInstances[$finalClassName] = $instance; @@ -4024,54 +4023,6 @@ class GeneralUtility return $instance; } - /** - * Speed optimized alternative to ReflectionClass::newInstanceArgs() - * - * @param string $className Name of the class to instantiate - * @param array $arguments Arguments passed to self::makeInstance() thus the first one with index 0 holds the requested class name - * @return mixed - */ - protected static function instantiateClass($className, $arguments) - { - switch (count($arguments)) { - case 1: - $instance = new $className(); - break; - case 2: - $instance = new $className($arguments[1]); - break; - case 3: - $instance = new $className($arguments[1], $arguments[2]); - break; - case 4: - $instance = new $className($arguments[1], $arguments[2], $arguments[3]); - break; - case 5: - $instance = new $className($arguments[1], $arguments[2], $arguments[3], $arguments[4]); - break; - case 6: - $instance = new $className($arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5]); - break; - case 7: - $instance = new $className($arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5], $arguments[6]); - break; - case 8: - $instance = new $className($arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5], $arguments[6], $arguments[7]); - break; - case 9: - $instance = new $className($arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5], $arguments[6], $arguments[7], $arguments[8]); - break; - default: - // The default case for classes with constructors that have more than 8 arguments. - // This will fail when one of the arguments shall be passed by reference. - // In case we really need to support this edge case, we can implement the solution from here: https://review.typo3.org/26344 - $class = new \ReflectionClass($className); - array_shift($arguments); - $instance = $class->newInstanceArgs($arguments); - } - return $instance; - } - /** * Returns the class name for a new instance, taking into account * registered implementations for this class diff --git a/typo3/sysext/core/Tests/BaseTestCase.php b/typo3/sysext/core/Tests/BaseTestCase.php index e7e1d0974e2d495f801a22292695fad590bb211d..65b36de2906293d77b66815e5acd9ca8d9b5994b 100644 --- a/typo3/sysext/core/Tests/BaseTestCase.php +++ b/typo3/sysext/core/Tests/BaseTestCase.php @@ -225,14 +225,11 @@ abstract class BaseTestCase extends \PHPUnit_Framework_TestCase * * @param object $object The object to be invoked * @param string $name the name of the method to call + * @param mixed $arguments * @return mixed */ - protected function callInaccessibleMethod($object, $name) + protected function callInaccessibleMethod($object, $name, ...$arguments) { - // Remove first two arguments ($object and $name) - $arguments = func_get_args(); - array_splice($arguments, 0, 2); - $reflectionObject = new \ReflectionObject($object); $reflectionMethod = $reflectionObject->getMethod($name); $reflectionMethod->setAccessible(true); diff --git a/typo3/sysext/core/Tests/Functional/DataHandling/IRRE/AbstractTestCase.php b/typo3/sysext/core/Tests/Functional/DataHandling/IRRE/AbstractTestCase.php index 54e52403bce1747d83616a0bbe5135d59bde3d75..e22e34789b6f948ed48895676f9c96b9da539327 100644 --- a/typo3/sysext/core/Tests/Functional/DataHandling/IRRE/AbstractTestCase.php +++ b/typo3/sysext/core/Tests/Functional/DataHandling/IRRE/AbstractTestCase.php @@ -439,14 +439,6 @@ abstract class AbstractTestCase extends \TYPO3\CMS\Core\Tests\FunctionalTestCase return $result; } - /** - * @return string - */ - protected function combine() - { - return implode(':', func_get_args()); - } - /** * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication */ diff --git a/typo3/sysext/core/Tests/Functional/Framework/Constraint/RequestSection/AbstractRecordConstraint.php b/typo3/sysext/core/Tests/Functional/Framework/Constraint/RequestSection/AbstractRecordConstraint.php index d1c808c49b0d62aeec31f6dbd4e736ace522f128..35ac7208fa40bdcbe0682329809dbc8b66d3b2ea 100644 --- a/typo3/sysext/core/Tests/Functional/Framework/Constraint/RequestSection/AbstractRecordConstraint.php +++ b/typo3/sysext/core/Tests/Functional/Framework/Constraint/RequestSection/AbstractRecordConstraint.php @@ -58,9 +58,8 @@ abstract class AbstractRecordConstraint extends \PHPUnit_Framework_Constraint return $this; } - public function setValues() + public function setValues(...$values) { - $values = func_get_args(); $this->values = $values; return $this; } diff --git a/typo3/sysext/core/Tests/Functional/Framework/Frontend/Response.php b/typo3/sysext/core/Tests/Functional/Framework/Frontend/Response.php index 7e62bf85abd07b3687a7c740a8555ffa8204739f..399cbb626e1bd02af91e69371d98fe3348f47bb7 100644 --- a/typo3/sysext/core/Tests/Functional/Framework/Frontend/Response.php +++ b/typo3/sysext/core/Tests/Functional/Framework/Frontend/Response.php @@ -90,14 +90,13 @@ class Response } /** + * @param mixed $sectionIdentifiers * @return NULL|array|ResponseSection[] */ - public function getResponseSections() + public function getResponseSections(...$sectionIdentifiers) { - $sectionIdentifiers = func_get_args(); - if (empty($sectionIdentifiers)) { - $sectionIdentifiers = array('Default'); + $sectionIdentifiers = ['Default']; } $sections = array(); diff --git a/typo3/sysext/core/Tests/Unit/Configuration/TypoScript/ConditionMatching/Fixtures/ConditionMatcherUserFuncs.php b/typo3/sysext/core/Tests/Unit/Configuration/TypoScript/ConditionMatching/Fixtures/ConditionMatcherUserFuncs.php index 174ec348945b84e057638389595c72d3a25f04e9..a924f7a8aaa2fe7d3052e297b2c051ba58157032 100644 --- a/typo3/sysext/core/Tests/Unit/Configuration/TypoScript/ConditionMatching/Fixtures/ConditionMatcherUserFuncs.php +++ b/typo3/sysext/core/Tests/Unit/Configuration/TypoScript/ConditionMatching/Fixtures/ConditionMatcherUserFuncs.php @@ -20,18 +20,18 @@ namespace { function user_testFunctionWithSingleArgument() { - return count(func_get_args()) === 1; + return func_num_args() === 1; } function user_testFunctionWithThreeArguments() { - return count(func_get_args()) === 3; + return func_num_args() === 3; } - function user_testFunctionWithThreeArgumentsSpaces() + function user_testFunctionWithThreeArgumentsSpaces(...$arguments) { $result = true; - foreach (func_get_args() as $argument) { + foreach ($arguments as $argument) { $result &= (trim($argument) == $argument); } return $result; diff --git a/typo3/sysext/core/Tests/Unit/Resource/Driver/LocalDriverTest.php b/typo3/sysext/core/Tests/Unit/Resource/Driver/LocalDriverTest.php index 2fceb280ad11aec6d3b6f1afb815fe7f2757173b..904a693b827b990d810408622c856747e2d2a222 100644 --- a/typo3/sysext/core/Tests/Unit/Resource/Driver/LocalDriverTest.php +++ b/typo3/sysext/core/Tests/Unit/Resource/Driver/LocalDriverTest.php @@ -753,12 +753,12 @@ class LocalDriverTest extends \TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase * As it is static we are using an exception to test if it is really called and works * * @static + * @param string $itemName * @throws \InvalidArgumentException * @see getFileListCallsConfiguredCallbackFunction */ - public static function callbackStaticTestFunction() + public static function callbackStaticTestFunction($itemName) { - list($itemName) = func_get_args(); if ($itemName === 'file2') { throw new \InvalidArgumentException('$itemName', 1336159604); } diff --git a/typo3/sysext/extbase/Tests/Unit/Property/TypeConverter/PersistentObjectConverterTest.php b/typo3/sysext/extbase/Tests/Unit/Property/TypeConverter/PersistentObjectConverterTest.php index f35e021e59d2d84824d76a1f2c412ee58073dd16..d4a3c5f081c37ef8842883095218568a942c1e52 100644 --- a/typo3/sysext/extbase/Tests/Unit/Property/TypeConverter/PersistentObjectConverterTest.php +++ b/typo3/sysext/extbase/Tests/Unit/Property/TypeConverter/PersistentObjectConverterTest.php @@ -73,13 +73,12 @@ class PersistentObjectConverterTest extends UnitTestCase $this->mockObjectManager = $this->getMock(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface::class); $this->mockObjectManager->expects($this->any()) ->method('get') - ->will($this->returnCallback(function () { - $args = func_get_args(); - $reflectionClass = new \ReflectionClass(array_shift($args)); - if (empty($args)) { + ->will($this->returnCallback(function ($className, ...$arguments) { + $reflectionClass = new \ReflectionClass($className); + if (empty($arguments)) { return $reflectionClass->newInstance(); } else { - return $reflectionClass->newInstanceArgs($args); + return $reflectionClass->newInstanceArgs($arguments); } })); $this->inject($this->converter, 'objectManager', $this->mockObjectManager); diff --git a/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php b/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php index ba46e80f888cd786a70c5760e800de7b819f4969..c7ce105162460b7dc658488abe30560068cbb5b1 100755 --- a/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php +++ b/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php @@ -183,12 +183,15 @@ class ContentObjectRendererTest extends \TYPO3\CMS\Core\Tests\UnitTestCase /** * Handles the arguments that have been sent to the getImgResource hook. * - * @return array + * @param string $file + * @param array $fileArray + * @param $imageResource + * @param \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $parent + * @return array * @see getImgResourceHookGetsCalled */ - public function isGetImgResourceHookCalledCallback() + public function isGetImgResourceHookCalledCallback($file, $fileArray, $imageResource, $parent) { - list($file, $fileArray, $imageResource, $parent) = func_get_args(); $this->assertEquals('typo3/clear.gif', $file); $this->assertEquals('typo3/clear.gif', $imageResource['origFile']); $this->assertTrue(is_array($fileArray)); @@ -3550,12 +3553,15 @@ class ContentObjectRendererTest extends \TYPO3\CMS\Core\Tests\UnitTestCase /** * Handles the arguments that have been sent to the getImgResource hook. * - * @return string + * @param array $sourceRenderConfiguration + * @param array $sourceConfiguration + * @param $oneSourceCollection + * @param $parent + * @return string * @see getImageSourceCollectionHookCalled */ - public function isGetOneSourceCollectionCalledCallback() + public function isGetOneSourceCollectionCalledCallback($sourceRenderConfiguration, $sourceConfiguration, $oneSourceCollection, $parent) { - list($sourceRenderConfiguration, $sourceConfiguration, $oneSourceCollection, $parent) = func_get_args(); $this->assertTrue(is_array($sourceRenderConfiguration)); $this->assertTrue(is_array($sourceConfiguration)); return 'isGetOneSourceCollectionCalledCallback'; diff --git a/typo3/sysext/frontend/Tests/Unit/Page/PageRepositoryTest.php b/typo3/sysext/frontend/Tests/Unit/Page/PageRepositoryTest.php index 8c623a288e91f148ba862201c9ef5add4b101154..0811c52c602a281a6f1722daf7b8c3bf0f2c4200 100644 --- a/typo3/sysext/frontend/Tests/Unit/Page/PageRepositoryTest.php +++ b/typo3/sysext/frontend/Tests/Unit/Page/PageRepositoryTest.php @@ -73,10 +73,13 @@ class PageRepositoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase /** * Handles the arguments that have been sent to the getPage_preProcess hook + * + * @param int $uid + * @param $disableGroupAccessCheck + * @param \TYPO3\CMS\Frontend\Page\PageRepository $parent */ - public function isGetPagePreProcessCalledCallback() + public function isGetPagePreProcessCalledCallback($uid, $disableGroupAccessCheck, $parent) { - list($uid, $disableGroupAccessCheck, $parent) = func_get_args(); $this->assertEquals(42, $uid); $this->assertFalse($disableGroupAccessCheck); $this->assertTrue($parent instanceof \TYPO3\CMS\Frontend\Page\PageRepository); diff --git a/typo3/sysext/saltedpasswords/Classes/SaltedPasswordService.php b/typo3/sysext/saltedpasswords/Classes/SaltedPasswordService.php index d3ec11ed026e71ea6d4c8ef21c5a8381da4f8227..9accafe809a99227af0fb8abe277ae9705fe22bf 100644 --- a/typo3/sysext/saltedpasswords/Classes/SaltedPasswordService.php +++ b/typo3/sysext/saltedpasswords/Classes/SaltedPasswordService.php @@ -238,14 +238,13 @@ class SaltedPasswordService extends \TYPO3\CMS\Sv\AbstractAuthenticationService * parameters. The syntax is the same as for sprintf() * * @param string $message Message to output + * @param string $params * @return void * @see \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog() */ - public function writeLogMessage($message) + public function writeLogMessage($message, ...$params) { - if (func_num_args() > 1) { - $params = func_get_args(); - array_shift($params); + if (!empty($params)) { $message = vsprintf($message, $params); } if (TYPO3_MODE === 'BE') { diff --git a/typo3/sysext/workspaces/Classes/Service/GridDataService.php b/typo3/sysext/workspaces/Classes/Service/GridDataService.php index 16c0677514f16d60ad6d48c7f284c190eb70992c..c0646188617c7ef1f355a6121d94662cabcf049b 100644 --- a/typo3/sysext/workspaces/Classes/Service/GridDataService.php +++ b/typo3/sysext/workspaces/Classes/Service/GridDataService.php @@ -619,12 +619,14 @@ class GridDataService * Emits a signal to be handled by any registered slots. * * @param string $signalName Name of the signal + * @param mixed $arguments * @return array */ - protected function emitSignal($signalName) + protected function emitSignal($signalName, ...$arguments) { // Arguments are always ($this, [method argument], [method argument], ...) - $signalArguments = array_merge(array($this), array_slice(func_get_args(), 1)); + $signalArguments = $arguments + array_unshift($signalArguments, $this); $slotReturn = $this->getSignalSlotDispatcher()->dispatch(\TYPO3\CMS\Workspaces\Service\GridDataService::class, $signalName, $signalArguments); return array_slice($slotReturn, 1); }