Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit eb71aaf

Browse filesBrowse files
minor #28436 Remove all usages of call_user_func_array() (nicolas-grekas)
This PR was merged into the 4.2-dev branch. Discussion ---------- Remove all usages of call_user_func_array() | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Because it's cleaner :) (and it saves creating one extra dummy array) Commits ------- b2718d7 Remove all usages of call_user_func_array()
2 parents 2879baf + b2718d7 commit eb71aaf
Copy full SHA for eb71aaf

File tree

Expand file treeCollapse file tree

27 files changed

+38
-41
lines changed
Filter options
Expand file treeCollapse file tree

27 files changed

+38
-41
lines changed

‎src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPass.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ private function findAndSortTags($tagName, ContainerBuilder $container)
146146

147147
if ($sortedTags) {
148148
krsort($sortedTags);
149-
$sortedTags = \call_user_func_array('array_merge', $sortedTags);
149+
$sortedTags = array_merge(...$sortedTags);
150150
}
151151

152152
return $sortedTags;

‎src/Symfony/Bridge/Monolog/Logger.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Monolog/Logger.php
+2-4Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
use Symfony\Contracts\Service\ResetInterface;
1818

1919
/**
20-
* Logger.
21-
*
2220
* @author Fabien Potencier <fabien@symfony.com>
2321
*/
2422
class Logger extends BaseLogger implements DebugLoggerInterface, ResetInterface
@@ -29,7 +27,7 @@ class Logger extends BaseLogger implements DebugLoggerInterface, ResetInterface
2927
public function getLogs(/* Request $request = null */)
3028
{
3129
if ($logger = $this->getDebugLogger()) {
32-
return \call_user_func_array(array($logger, 'getLogs'), \func_get_args());
30+
return $logger->getLogs(...\func_get_args());
3331
}
3432

3533
return array();
@@ -41,7 +39,7 @@ public function getLogs(/* Request $request = null */)
4139
public function countErrors(/* Request $request = null */)
4240
{
4341
if ($logger = $this->getDebugLogger()) {
44-
return \call_user_func_array(array($logger, 'countErrors'), \func_get_args());
42+
return $logger->countErrors(...\func_get_args());
4543
}
4644

4745
return 0;

‎src/Symfony/Bridge/Twig/Tests/Extension/DumpExtensionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Tests/Extension/DumpExtensionTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function testDump($context, $args, $expectedOutput, $debug = true)
7676
array_unshift($args, $context);
7777
array_unshift($args, $twig);
7878

79-
$dump = \call_user_func_array(array($extension, 'dump'), $args);
79+
$dump = $extension->dump(...$args);
8080

8181
if ($debug) {
8282
$this->assertStringStartsWith('<script>', $dump);

‎src/Symfony/Bundle/FrameworkBundle/Templating/Helper/StopwatchHelper.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Templating/Helper/StopwatchHelper.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __call($method, $arguments = array())
3737
{
3838
if (null !== $this->stopwatch) {
3939
if (method_exists($this->stopwatch, $method)) {
40-
return \call_user_func_array(array($this->stopwatch, $method), $arguments);
40+
return $this->stopwatch->{$method}(...$arguments);
4141
}
4242

4343
throw new \BadMethodCallException(sprintf('Method "%s" of Stopwatch does not exist', $method));

‎src/Symfony/Bundle/SecurityBundle/Debug/WrappedListener.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/SecurityBundle/Debug/WrappedListener.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function handle(GetResponseEvent $event)
5353
*/
5454
public function __call($method, $arguments)
5555
{
56-
return \call_user_func_array(array($this->listener, $method), $arguments);
56+
return $this->listener->{$method}(...$arguments);
5757
}
5858

5959
public function getWrappedListener(): ListenerInterface

‎src/Symfony/Component/Cache/Traits/RedisProxy.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Traits/RedisProxy.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function __call($method, array $args)
3232
{
3333
$this->ready ?: $this->ready = $this->initializer->__invoke($this->redis);
3434

35-
return \call_user_func_array(array($this->redis, $method), $args);
35+
return $this->redis->{$method}(...$args);
3636
}
3737

3838
public function hscan($strKey, &$iIterator, $strPattern = null, $iCount = null)

‎src/Symfony/Component/Cache/Traits/RedisTrait.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Traits/RedisTrait.php
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,13 +336,13 @@ private function pipeline(\Closure $generator)
336336
// see https://github.com/nrk/predis/issues/267#issuecomment-123781423
337337
$results = array();
338338
foreach ($generator() as $command => $args) {
339-
$results[] = \call_user_func_array(array($this->redis, $command), $args);
339+
$results[] = $this->redis->{$command}(...$args);
340340
$ids[] = $args[0];
341341
}
342342
} elseif ($this->redis instanceof \Predis\Client) {
343343
$results = $this->redis->pipeline(function ($redis) use ($generator, &$ids) {
344344
foreach ($generator() as $command => $args) {
345-
\call_user_func_array(array($redis, $command), $args);
345+
$redis->{$command}(...$args);
346346
$ids[] = $args[0];
347347
}
348348
});
@@ -353,7 +353,7 @@ private function pipeline(\Closure $generator)
353353
$connections[$h] = array($this->redis->_instance($h), -1);
354354
$connections[$h][0]->multi(\Redis::PIPELINE);
355355
}
356-
\call_user_func_array(array($connections[$h][0], $command), $args);
356+
$connections[$h][0]->{$command}(...$args);
357357
$results[] = array($h, ++$connections[$h][1]);
358358
$ids[] = $args[0];
359359
}
@@ -366,7 +366,7 @@ private function pipeline(\Closure $generator)
366366
} else {
367367
$this->redis->multi(\Redis::PIPELINE);
368368
foreach ($generator() as $command => $args) {
369-
\call_user_func_array(array($this->redis, $command), $args);
369+
$this->redis->{$command}(...$args);
370370
$ids[] = $args[0];
371371
}
372372
$results = $this->redis->exec();

‎src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function testPrototypeNodeSpecificOption($method, $args)
4343
{
4444
$node = new ArrayNodeDefinition('root');
4545

46-
\call_user_func_array(array($node, $method), $args);
46+
$node->{$method}(...$args);
4747

4848
$node->getNode();
4949
}

‎src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/ContainerBuilder.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,7 @@ private function createService(Definition $definition, array &$inlineServices, $
11141114
}
11151115

11161116
if (null !== $factory) {
1117-
$service = \call_user_func_array($factory, $arguments);
1117+
$service = $factory(...$arguments);
11181118

11191119
if (!$definition->isDeprecated() && \is_array($factory) && \is_string($factory[0])) {
11201120
$r = new \ReflectionClass($factory[0]);
@@ -1563,7 +1563,7 @@ private function callMethod($service, $call, array &$inlineServices)
15631563
}
15641564
}
15651565

1566-
\call_user_func_array(array($service, $call[0]), $this->doResolveServices($this->getParameterBag()->unescapeValue($this->getParameterBag()->resolveValue($call[1])), $inlineServices));
1566+
$service->{$call[0]}(...$this->doResolveServices($this->getParameterBag()->unescapeValue($this->getParameterBag()->resolveValue($call[1])), $inlineServices));
15671567
}
15681568

15691569
/**

‎src/Symfony/Component/DependencyInjection/Loader/Configurator/AbstractConfigurator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Loader/Configurator/AbstractConfigurator.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ abstract class AbstractConfigurator
2828
public function __call($method, $args)
2929
{
3030
if (method_exists($this, 'set'.$method)) {
31-
return \call_user_func_array(array($this, 'set'.$method), $args);
31+
return $this->{'set'.$method}(...$args);
3232
}
3333

3434
throw new \BadMethodCallException(sprintf('Call to undefined method %s::%s()', \get_class($this), $method));

‎src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ public function reset()
230230
*/
231231
public function __call($method, $arguments)
232232
{
233-
return \call_user_func_array(array($this->dispatcher, $method), $arguments);
233+
return $this->dispatcher->{$method}(...$arguments);
234234
}
235235

236236
/**

‎src/Symfony/Component/ExpressionLanguage/ExpressionFunction.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/ExpressionLanguage/ExpressionFunction.php
+1-3Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ public static function fromPhp($phpFunctionName, $expressionFunctionName = null)
9090
};
9191

9292
$evaluator = function () use ($phpFunctionName) {
93-
$args = \func_get_args();
94-
95-
return \call_user_func_array($phpFunctionName, array_splice($args, 1));
93+
return $phpFunctionName(...\array_slice(\func_get_args(), 1));
9694
};
9795

9896
return new self($expressionFunctionName ?: end($parts), $compiler, $evaluator);

‎src/Symfony/Component/ExpressionLanguage/Node/FunctionNode.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/ExpressionLanguage/Node/FunctionNode.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function compile(Compiler $compiler)
3737

3838
$function = $compiler->getFunction($this->attributes['name']);
3939

40-
$compiler->raw(\call_user_func_array($function['compiler'], $arguments));
40+
$compiler->raw($function['compiler'](...$arguments));
4141
}
4242

4343
public function evaluate($functions, $values)
@@ -47,7 +47,7 @@ public function evaluate($functions, $values)
4747
$arguments[] = $node->evaluate($functions, $values);
4848
}
4949

50-
return \call_user_func_array($functions[$this->attributes['name']]['evaluator'], $arguments);
50+
return $functions[$this->attributes['name']]['evaluator'](...$arguments);
5151
}
5252

5353
public function toArray()

‎src/Symfony/Component/ExpressionLanguage/Node/GetAttrNode.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/ExpressionLanguage/Node/GetAttrNode.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function evaluate($functions, $values)
8686
throw new \RuntimeException(sprintf('Unable to call method "%s" of object "%s".', $this->nodes['attribute']->attributes['value'], \get_class($obj)));
8787
}
8888

89-
return \call_user_func_array($toCall, $this->nodes['arguments']->evaluate($functions, $values));
89+
return $toCall(...array_values($this->nodes['arguments']->evaluate($functions, $values)));
9090

9191
case self::ARRAY_CALL:
9292
$array = $this->nodes['node']->evaluate($functions, $values);

‎src/Symfony/Component/Filesystem/Filesystem.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Filesystem/Filesystem.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ private static function box($func)
744744
self::$lastError = null;
745745
\set_error_handler(__CLASS__.'::handleError');
746746
try {
747-
$result = \call_user_func_array($func, \array_slice(\func_get_args(), 1));
747+
$result = $func(...\array_slice(\func_get_args(), 1));
748748
\restore_error_handler();
749749

750750
return $result;

‎src/Symfony/Component/HttpKernel/HttpKernel.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/HttpKernel.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ private function handleRaw(Request $request, int $type = self::MASTER_REQUEST)
147147
$arguments = $event->getArguments();
148148

149149
// call controller
150-
$response = \call_user_func_array($controller, $arguments);
150+
$response = $controller(...$arguments);
151151

152152
// view
153153
if (!$response instanceof Response) {

‎src/Symfony/Component/HttpKernel/Tests/Fragment/FragmentHandlerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Tests/Fragment/FragmentHandlerTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ protected function getHandler($returnValue, $arguments = array())
8888
;
8989

9090
if ($arguments) {
91-
\call_user_func_array(array($e, 'with'), $arguments);
91+
$e->with(...$arguments);
9292
}
9393

9494
$handler = new FragmentHandler($this->requestStack);

‎src/Symfony/Component/HttpKernel/Tests/HttpCache/EsiTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Tests/HttpCache/EsiTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ protected function getCache($request, $response)
234234
if (\is_array($response)) {
235235
$cache->expects($this->any())
236236
->method('handle')
237-
->will(\call_user_func_array(array($this, 'onConsecutiveCalls'), $response))
237+
->will($this->onConsecutiveCalls(...$response))
238238
;
239239
} else {
240240
$cache->expects($this->any())

‎src/Symfony/Component/HttpKernel/Tests/HttpCache/SsiTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Tests/HttpCache/SsiTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ protected function getCache($request, $response)
201201
if (\is_array($response)) {
202202
$cache->expects($this->any())
203203
->method('handle')
204-
->will(\call_user_func_array(array($this, 'onConsecutiveCalls'), $response))
204+
->will($this->onConsecutiveCalls(...$response))
205205
;
206206
} else {
207207
$cache->expects($this->any())

‎src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ public function testHandleWhenTheControllerDoesNotReturnAResponse()
227227
$first = $e->getTrace()[0];
228228

229229
// `file` index the array starting at 0, and __FILE__ starts at 1
230-
$line = file($first['file'])[$first['line'] - 1];
231-
$this->assertContains('call_user_func_array', $line);
230+
$line = file($first['file'])[$first['line'] - 2];
231+
$this->assertContains('// call controller', $line);
232232
}
233233

234234
public function testHandleWhenTheControllerDoesNotReturnAResponseButAViewIsRegistered()
@@ -274,7 +274,7 @@ public function testHandleAllowChangingControllerAndArguments()
274274
$oldArguments = $event->getArguments();
275275

276276
$newController = function ($id) use ($oldController, $oldArguments) {
277-
$response = \call_user_func_array($oldController, $oldArguments);
277+
$response = $oldController(...$oldArguments);
278278

279279
$response->headers->set('X-Id', $id);
280280

‎src/Symfony/Component/Intl/Tests/Locale/LocaleTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Intl/Tests/Locale/LocaleTest.php
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Intl\Tests\Locale;
1313

14+
use Symfony\Component\Intl\Locale\Locale;
15+
1416
class LocaleTest extends AbstractLocaleTest
1517
{
1618
/**
@@ -172,6 +174,6 @@ protected function call($methodName)
172174
{
173175
$args = \array_slice(\func_get_args(), 1);
174176

175-
return \call_user_func_array(array('Symfony\Component\Intl\Locale\Locale', $methodName), $args);
177+
return Locale::{$methodName}(...$args);
176178
}
177179
}

‎src/Symfony/Component/Intl/Tests/Locale/Verification/LocaleTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Intl/Tests/Locale/Verification/LocaleTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ protected function call($methodName)
3333
{
3434
$args = \array_slice(\func_get_args(), 1);
3535

36-
return \call_user_func_array(array('Locale', $methodName), $args);
36+
return \Locale::{$methodName}(...$args);
3737
}
3838
}

‎src/Symfony/Component/Lock/Store/RedisStore.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Lock/Store/RedisStore.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ private function evaluate(string $script, string $resource, array $args)
139139
}
140140

141141
if ($this->redis instanceof \Predis\Client) {
142-
return \call_user_func_array(array($this->redis, 'eval'), array_merge(array($script, 1, $resource), $args));
142+
return $this->redis->eval(...array_merge(array($script, 1, $resource), $args));
143143
}
144144

145145
throw new InvalidArgumentException(sprintf('%s() expects being initialized with a Redis, RedisArray, RedisCluster or Predis\Client, %s given', __METHOD__, \is_object($this->redis) ? \get_class($this->redis) : \gettype($this->redis)));

‎src/Symfony/Component/PropertyInfo/PropertyInfoCacheExtractor.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/PropertyInfo/PropertyInfoCacheExtractor.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ private function extract(string $method, array $arguments)
9999
$serializedArguments = serialize($arguments);
100100
} catch (\Exception $exception) {
101101
// If arguments are not serializable, skip the cache
102-
return \call_user_func_array(array($this->propertyInfoExtractor, $method), $arguments);
102+
return $this->propertyInfoExtractor->{$method}(...$arguments);
103103
}
104104

105105
// Calling rawurlencode escapes special characters not allowed in PSR-6's keys
@@ -115,7 +115,7 @@ private function extract(string $method, array $arguments)
115115
return $this->arrayCache[$key] = $item->get();
116116
}
117117

118-
$value = \call_user_func_array(array($this->propertyInfoExtractor, $method), $arguments);
118+
$value = $this->propertyInfoExtractor->{$method}(...$arguments);
119119
$item->set($value);
120120
$this->cacheItemPool->save($item);
121121

‎src/Symfony/Component/PropertyInfo/PropertyInfoExtractor.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/PropertyInfo/PropertyInfoExtractor.php
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ public function isInitializable(string $class, string $property, array $context
106106
private function extract(iterable $extractors, string $method, array $arguments)
107107
{
108108
foreach ($extractors as $extractor) {
109-
$value = \call_user_func_array(array($extractor, $method), $arguments);
110-
if (null !== $value) {
109+
if (null !== $value = $extractor->{$method}(...$arguments)) {
111110
return $value;
112111
}
113112
}

‎src/Symfony/Component/Translation/DataCollectorTranslator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/DataCollectorTranslator.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public function getFallbackLocales()
108108
*/
109109
public function __call($method, $args)
110110
{
111-
return \call_user_func_array(array($this->translator, $method), $args);
111+
return $this->translator->{$method}(...$args);
112112
}
113113

114114
/**

‎src/Symfony/Component/Translation/LoggingTranslator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/LoggingTranslator.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function getFallbackLocales()
107107
*/
108108
public function __call($method, $args)
109109
{
110-
return \call_user_func_array(array($this->translator, $method), $args);
110+
return $this->translator->{$method}(...$args);
111111
}
112112

113113
/**

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.