From fd266c7da93c10801a0b92c4d4b9fa31202c8c6f Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 19 Nov 2014 19:42:26 +0100 Subject: [PATCH] Remove all calls to call_user_func() --- .../LazyProxy/Instantiator/RuntimeInstantiator.php | 2 +- src/Symfony/Component/Config/Util/XmlUtils.php | 2 +- src/Symfony/Component/Console/Command/Command.php | 4 ++-- src/Symfony/Component/Console/Helper/DialogHelper.php | 2 +- src/Symfony/Component/Console/Helper/ProcessHelper.php | 2 +- src/Symfony/Component/Console/Helper/ProgressBar.php | 2 +- .../Component/Console/Helper/QuestionHelper.php | 3 ++- src/Symfony/Component/CssSelector/XPath/Translator.php | 10 +++++----- src/Symfony/Component/Debug/DebugClassLoader.php | 5 +++-- src/Symfony/Component/Debug/ErrorHandler.php | 4 ++-- src/Symfony/Component/Debug/ExceptionHandler.php | 4 ++-- .../Component/DependencyInjection/ContainerBuilder.php | 2 +- .../LazyProxy/Instantiator/RealServiceInstantiator.php | 2 +- .../DependencyInjection/Loader/ClosureLoader.php | 2 +- .../EventDispatcher/Debug/WrappedListener.php | 3 ++- .../Component/EventDispatcher/EventDispatcher.php | 2 +- .../Component/Finder/Iterator/CustomFilterIterator.php | 2 +- src/Symfony/Component/Form/CallbackTransformer.php | 8 ++++++-- .../Extension/Validator/Constraints/FormValidator.php | 2 +- src/Symfony/Component/HttpFoundation/JsonResponse.php | 5 ++--- src/Symfony/Component/HttpFoundation/Request.php | 4 ++-- .../Component/HttpFoundation/StreamedResponse.php | 4 ++-- .../Session/Storage/Handler/PdoSessionHandlerTest.php | 6 +++--- src/Symfony/Component/Process/Process.php | 3 ++- .../Serializer/Normalizer/GetSetMethodNormalizer.php | 6 +++--- .../Serializer/Normalizer/PropertyNormalizer.php | 2 +- src/Symfony/Component/Templating/PhpEngine.php | 6 ++++-- .../Component/Translation/PluralizationRules.php | 2 +- .../Validator/Constraints/CallbackValidator.php | 2 +- .../Validator/Constraints/ChoiceValidator.php | 9 ++++----- .../Component/VarDumper/Cloner/AbstractCloner.php | 6 +++--- .../Component/VarDumper/Dumper/AbstractDumper.php | 3 ++- src/Symfony/Component/VarDumper/VarDumper.php | 6 +++--- 33 files changed, 68 insertions(+), 59 deletions(-) diff --git a/src/Symfony/Bridge/ProxyManager/LazyProxy/Instantiator/RuntimeInstantiator.php b/src/Symfony/Bridge/ProxyManager/LazyProxy/Instantiator/RuntimeInstantiator.php index 8a98b29f6f492..3374b4f399e25 100644 --- a/src/Symfony/Bridge/ProxyManager/LazyProxy/Instantiator/RuntimeInstantiator.php +++ b/src/Symfony/Bridge/ProxyManager/LazyProxy/Instantiator/RuntimeInstantiator.php @@ -51,7 +51,7 @@ public function instantiateProxy(ContainerInterface $container, Definition $defi return $this->factory->createProxy( $definition->getClass(), function (&$wrappedInstance, LazyLoadingInterface $proxy) use ($realInstantiator) { - $wrappedInstance = call_user_func($realInstantiator); + $wrappedInstance = $realInstantiator(); $proxy->setProxyInitializer(null); diff --git a/src/Symfony/Component/Config/Util/XmlUtils.php b/src/Symfony/Component/Config/Util/XmlUtils.php index 84739193624a4..34a10531c1d5d 100644 --- a/src/Symfony/Component/Config/Util/XmlUtils.php +++ b/src/Symfony/Component/Config/Util/XmlUtils.php @@ -75,7 +75,7 @@ public static function loadFile($file, $schemaOrCallable = null) $e = null; if (is_callable($schemaOrCallable)) { try { - $valid = call_user_func($schemaOrCallable, $dom, $internalErrors); + $valid = $schemaOrCallable($dom, $internalErrors); } catch (\Exception $e) { $valid = false; } diff --git a/src/Symfony/Component/Console/Command/Command.php b/src/Symfony/Component/Console/Command/Command.php index c9b7534e94578..c2017037752d1 100644 --- a/src/Symfony/Component/Console/Command/Command.php +++ b/src/Symfony/Component/Console/Command/Command.php @@ -246,8 +246,8 @@ public function run(InputInterface $input, OutputInterface $output) $input->validate(); - if ($this->code) { - $statusCode = call_user_func($this->code, $input, $output); + if ($code = $this->code) { + $statusCode = $code($input, $output); } else { $statusCode = $this->execute($input, $output); } diff --git a/src/Symfony/Component/Console/Helper/DialogHelper.php b/src/Symfony/Component/Console/Helper/DialogHelper.php index 589568ec78892..1fdc0f60e1d6f 100644 --- a/src/Symfony/Component/Console/Helper/DialogHelper.php +++ b/src/Symfony/Component/Console/Helper/DialogHelper.php @@ -467,7 +467,7 @@ private function validateAttempts($interviewer, OutputInterface $output, $valida } try { - return call_user_func($validator, $interviewer()); + return $validator($interviewer()); } catch (\Exception $error) { } } diff --git a/src/Symfony/Component/Console/Helper/ProcessHelper.php b/src/Symfony/Component/Console/Helper/ProcessHelper.php index 0c9da73947623..8123e2ab52393 100644 --- a/src/Symfony/Component/Console/Helper/ProcessHelper.php +++ b/src/Symfony/Component/Console/Helper/ProcessHelper.php @@ -117,7 +117,7 @@ public function wrapCallback(OutputInterface $output, Process $process, $callbac $output->write($formatter->progress(spl_object_hash($process), $that->escapeString($buffer), Process::ERR === $type)); if (null !== $callback) { - call_user_func($callback, $type, $buffer); + $callback($type, $buffer); } }; } diff --git a/src/Symfony/Component/Console/Helper/ProgressBar.php b/src/Symfony/Component/Console/Helper/ProgressBar.php index bc3471b2971e9..64a9d4fcaabcc 100644 --- a/src/Symfony/Component/Console/Helper/ProgressBar.php +++ b/src/Symfony/Component/Console/Helper/ProgressBar.php @@ -438,7 +438,7 @@ public function display() $messages = $this->messages; $this->overwrite(preg_replace_callback("{%([a-z\-_]+)(?:\:([^%]+))?%}i", function ($matches) use ($self, $output, $messages) { if ($formatter = $self::getPlaceholderFormatterDefinition($matches[1])) { - $text = call_user_func($formatter, $self, $output); + $text = $formatter($self, $output); } elseif (isset($messages[$matches[1]])) { $text = $messages[$matches[1]]; } else { diff --git a/src/Symfony/Component/Console/Helper/QuestionHelper.php b/src/Symfony/Component/Console/Helper/QuestionHelper.php index c5e7aad444bac..cfc4c26c5537a 100644 --- a/src/Symfony/Component/Console/Helper/QuestionHelper.php +++ b/src/Symfony/Component/Console/Helper/QuestionHelper.php @@ -353,13 +353,14 @@ private function validateAttempts($interviewer, OutputInterface $output, Questio { $error = null; $attempts = $question->getMaxAttempts(); + $validator = $question->getValidator(); while (null === $attempts || $attempts--) { if (null !== $error) { $output->writeln($this->getHelperSet()->get('formatter')->formatBlock($error->getMessage(), 'error')); } try { - return call_user_func($question->getValidator(), $interviewer()); + return $validator($interviewer()); } catch (\Exception $error) { } } diff --git a/src/Symfony/Component/CssSelector/XPath/Translator.php b/src/Symfony/Component/CssSelector/XPath/Translator.php index 5675aa610646d..d72d33e5a3483 100644 --- a/src/Symfony/Component/CssSelector/XPath/Translator.php +++ b/src/Symfony/Component/CssSelector/XPath/Translator.php @@ -205,7 +205,7 @@ public function nodeToXPath(NodeInterface $node) throw new ExpressionErrorException(sprintf('Node "%s" not supported.', $node->getNodeName())); } - return call_user_func($this->nodeTranslators[$node->getNodeName()], $node, $this); + return $this->nodeTranslators[$node->getNodeName()]($node, $this); } /** @@ -223,7 +223,7 @@ public function addCombination($combiner, NodeInterface $xpath, NodeInterface $c throw new ExpressionErrorException(sprintf('Combiner "%s" not supported.', $combiner)); } - return call_user_func($this->combinationTranslators[$combiner], $this->nodeToXPath($xpath), $this->nodeToXPath($combinedXpath)); + return $this->combinationTranslators[$combiner]($this->nodeToXPath($xpath), $this->nodeToXPath($combinedXpath)); } /** @@ -240,7 +240,7 @@ public function addFunction(XPathExpr $xpath, FunctionNode $function) throw new ExpressionErrorException(sprintf('Function "%s" not supported.', $function->getName())); } - return call_user_func($this->functionTranslators[$function->getName()], $xpath, $function); + return $this->functionTranslators[$function->getName()]($xpath, $function); } /** @@ -257,7 +257,7 @@ public function addPseudoClass(XPathExpr $xpath, $pseudoClass) throw new ExpressionErrorException(sprintf('Pseudo-class "%s" not supported.', $pseudoClass)); } - return call_user_func($this->pseudoClassTranslators[$pseudoClass], $xpath); + return $this->pseudoClassTranslators[$pseudoClass]($xpath); } /** @@ -276,7 +276,7 @@ public function addAttributeMatching(XPathExpr $xpath, $operator, $attribute, $v throw new ExpressionErrorException(sprintf('Attribute matcher operator "%s" not supported.', $operator)); } - return call_user_func($this->attributeMatchingTranslators[$operator], $xpath, $attribute, $value); + return $this->attributeMatchingTranslators[$operator]($xpath, $attribute, $value); } /** diff --git a/src/Symfony/Component/Debug/DebugClassLoader.php b/src/Symfony/Component/Debug/DebugClassLoader.php index ac5536529496e..7f6a6447fa20e 100644 --- a/src/Symfony/Component/Debug/DebugClassLoader.php +++ b/src/Symfony/Component/Debug/DebugClassLoader.php @@ -150,12 +150,13 @@ public function loadClass($class) ErrorHandler::stackErrors(); try { + $classLoader = $this->classLoader; if ($this->isFinder) { - if ($file = $this->classLoader[0]->findFile($class)) { + if ($file = $classLoader[0]->findFile($class)) { require $file; } } else { - call_user_func($this->classLoader, $class); + $classLoader($class); $file = false; } } catch (\Exception $e) { diff --git a/src/Symfony/Component/Debug/ErrorHandler.php b/src/Symfony/Component/Debug/ErrorHandler.php index 458cb317717d2..3a35e7a223ef8 100644 --- a/src/Symfony/Component/Debug/ErrorHandler.php +++ b/src/Symfony/Component/Debug/ErrorHandler.php @@ -466,11 +466,11 @@ public function handleException(\Exception $exception, array $error = null) } } } - if (empty($this->exceptionHandler)) { + if (!$exceptionHandler = $this->exceptionHandler) { throw $exception; // Give back $exception to the native handler } try { - call_user_func($this->exceptionHandler, $exception); + $exceptionHandler($exception); } catch (\Exception $handlerException) { $this->exceptionHandler = null; $this->handleException($handlerException); diff --git a/src/Symfony/Component/Debug/ExceptionHandler.php b/src/Symfony/Component/Debug/ExceptionHandler.php index a0d03236de398..30d5d63f35a8d 100644 --- a/src/Symfony/Component/Debug/ExceptionHandler.php +++ b/src/Symfony/Component/Debug/ExceptionHandler.php @@ -104,7 +104,7 @@ public function setFileLinkFormat($format) */ public function handle(\Exception $exception) { - if (null === $this->handler || $exception instanceof OutOfMemoryException) { + if ($exception instanceof OutOfMemoryException || null === $handler = $this->handler) { $this->failSafeHandle($exception); return; @@ -125,7 +125,7 @@ public function handle(\Exception $exception) $this->caughtBuffer = null; try { - call_user_func($this->handler, $exception); + $handler($exception); $this->caughtLength = $caughtLength; } catch (\Exception $e) { if (!$caughtLength) { diff --git a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php index 1d091a097f2b1..0db84f2c847b3 100644 --- a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php +++ b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php @@ -992,7 +992,7 @@ public function createService(Definition $definition, $id, $tryProxy = true) throw new InvalidArgumentException(sprintf('The configure callable for class "%s" is not a callable.', get_class($service))); } - call_user_func($callable, $service); + $callable($service); } return $service; diff --git a/src/Symfony/Component/DependencyInjection/LazyProxy/Instantiator/RealServiceInstantiator.php b/src/Symfony/Component/DependencyInjection/LazyProxy/Instantiator/RealServiceInstantiator.php index cad9320039b14..4d6a9f05a9395 100644 --- a/src/Symfony/Component/DependencyInjection/LazyProxy/Instantiator/RealServiceInstantiator.php +++ b/src/Symfony/Component/DependencyInjection/LazyProxy/Instantiator/RealServiceInstantiator.php @@ -28,6 +28,6 @@ class RealServiceInstantiator implements InstantiatorInterface */ public function instantiateProxy(ContainerInterface $container, Definition $definition, $id, $realInstantiator) { - return call_user_func($realInstantiator); + return $realInstantiator(); } } diff --git a/src/Symfony/Component/DependencyInjection/Loader/ClosureLoader.php b/src/Symfony/Component/DependencyInjection/Loader/ClosureLoader.php index a5b4e5ad240e5..0dc9a90070bc9 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/ClosureLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/ClosureLoader.php @@ -40,7 +40,7 @@ public function __construct(ContainerBuilder $container) */ public function load($resource, $type = null) { - call_user_func($resource, $this->container); + $resource($this->container); } /** diff --git a/src/Symfony/Component/EventDispatcher/Debug/WrappedListener.php b/src/Symfony/Component/EventDispatcher/Debug/WrappedListener.php index c501662b07d1d..1a026d9257f54 100644 --- a/src/Symfony/Component/EventDispatcher/Debug/WrappedListener.php +++ b/src/Symfony/Component/EventDispatcher/Debug/WrappedListener.php @@ -56,7 +56,8 @@ public function __invoke(Event $event, $eventName, EventDispatcherInterface $dis $e = $this->stopwatch->start($this->name, 'event_listener'); - call_user_func($this->listener, $event, $eventName, $dispatcher); + $listener = $this->listener; + $listener($event, $eventName, $dispatcher); if ($e->isStarted()) { $e->stop(); diff --git a/src/Symfony/Component/EventDispatcher/EventDispatcher.php b/src/Symfony/Component/EventDispatcher/EventDispatcher.php index 222a937141254..328abb0026dd6 100644 --- a/src/Symfony/Component/EventDispatcher/EventDispatcher.php +++ b/src/Symfony/Component/EventDispatcher/EventDispatcher.php @@ -161,7 +161,7 @@ public function removeSubscriber(EventSubscriberInterface $subscriber) protected function doDispatch($listeners, $eventName, Event $event) { foreach ($listeners as $listener) { - call_user_func($listener, $event, $eventName, $this); + $listener($event, $eventName, $this); if ($event->isPropagationStopped()) { break; } diff --git a/src/Symfony/Component/Finder/Iterator/CustomFilterIterator.php b/src/Symfony/Component/Finder/Iterator/CustomFilterIterator.php index 36d79dbc97452..05580bdbd7bc7 100644 --- a/src/Symfony/Component/Finder/Iterator/CustomFilterIterator.php +++ b/src/Symfony/Component/Finder/Iterator/CustomFilterIterator.php @@ -53,7 +53,7 @@ public function accept() $fileinfo = $this->current(); foreach ($this->filters as $filter) { - if (false === call_user_func($filter, $fileinfo)) { + if (false === $filter($fileinfo)) { return false; } } diff --git a/src/Symfony/Component/Form/CallbackTransformer.php b/src/Symfony/Component/Form/CallbackTransformer.php index 03459d4e8a089..54fa55cd026f8 100644 --- a/src/Symfony/Component/Form/CallbackTransformer.php +++ b/src/Symfony/Component/Form/CallbackTransformer.php @@ -61,7 +61,9 @@ public function __construct($transform, $reverseTransform) */ public function transform($data) { - return call_user_func($this->transform, $data); + $t = $this->transform; + + return $t($data); } /** @@ -77,6 +79,8 @@ public function transform($data) */ public function reverseTransform($data) { - return call_user_func($this->reverseTransform, $data); + $r = $this->reverseTransform; + + return $r($data); } } diff --git a/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php b/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php index d4e6f466fcaed..2fe15dc2ea29c 100644 --- a/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php +++ b/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php @@ -198,7 +198,7 @@ private static function getValidationGroups(FormInterface $form) private static function resolveValidationGroups($groups, FormInterface $form) { if (!is_string($groups) && is_callable($groups)) { - $groups = call_user_func($groups, $form); + $groups = $groups($form); } return (array) $groups; diff --git a/src/Symfony/Component/HttpFoundation/JsonResponse.php b/src/Symfony/Component/HttpFoundation/JsonResponse.php index accd57cf3adc8..9425845f40b92 100644 --- a/src/Symfony/Component/HttpFoundation/JsonResponse.php +++ b/src/Symfony/Component/HttpFoundation/JsonResponse.php @@ -95,14 +95,13 @@ public function setCallback($callback = null) */ public function setData($data = array()) { - $errorHandler = null; - $errorHandler = set_error_handler(function () use (&$errorHandler) { + $errorHandler = set_error_handler(function ($type, $msg, $file, $line, $context) use (&$errorHandler) { if (JSON_ERROR_NONE !== json_last_error()) { return; } if ($errorHandler) { - call_user_func_array($errorHandler, func_get_args()); + $errorHandler($type, $msg, $file, $line, $context); } }); diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index 1871dde35088a..8455b0cc60828 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -1874,8 +1874,8 @@ private function getUrlencodedPrefix($string, $prefix) private static function createRequestFromFactory(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), $content = null) { - if (self::$requestFactory) { - $request = call_user_func(self::$requestFactory, $query, $request, $attributes, $cookies, $files, $server, $content); + if ($requestFactory = self::$requestFactory) { + $request = $requestFactory($query, $request, $attributes, $cookies, $files, $server, $content); if (!$request instanceof Request) { throw new \LogicException('The Request factory must return an instance of Symfony\Component\HttpFoundation\Request.'); diff --git a/src/Symfony/Component/HttpFoundation/StreamedResponse.php b/src/Symfony/Component/HttpFoundation/StreamedResponse.php index 38986e8aa7f84..f4d41bef5ce46 100644 --- a/src/Symfony/Component/HttpFoundation/StreamedResponse.php +++ b/src/Symfony/Component/HttpFoundation/StreamedResponse.php @@ -92,11 +92,11 @@ public function sendContent() $this->streamed = true; - if (null === $this->callback) { + if (null === $callback = $this->callback) { throw new \LogicException('The Response callback must not be null.'); } - call_user_func($this->callback); + $callback(); } /** diff --git a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php index ba06fccff9103..01cd42efe56a9 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php @@ -348,9 +348,9 @@ public function getAttribute($attribute) public function prepare($statement, $driverOptions = array()) { - return is_callable($this->prepareResult) - ? call_user_func($this->prepareResult, $statement, $driverOptions) - : $this->prepareResult; + return is_callable($prepareResult = $this->prepareResult) + ? $prepareResult($statement, $driverOptions) + : $prepareResult; } public function beginTransaction() diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index d1d0ae1066c2a..b376029c17da3 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -1289,7 +1289,7 @@ protected function buildCallback($callback) } if (null !== $callback) { - call_user_func($callback, $type, $data); + $callback($type, $data); } }; @@ -1369,6 +1369,7 @@ private function validateTimeout($timeout) private function readPipes($blocking, $close) { $result = $this->processPipes->readAndWrite($blocking, $close); + $callback = $this->callback; foreach ($result as $type => $data) { if (3 == $type) { diff --git a/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php index b15eefc6e487a..14391eb711214 100644 --- a/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php @@ -138,8 +138,8 @@ public function normalize($object, $format = null, array $context = array()) if ($context['circular_reference_limit'][$objectHash] >= $this->circularReferenceLimit) { unset($context['circular_reference_limit'][$objectHash]); - if ($this->circularReferenceHandler) { - return call_user_func($this->circularReferenceHandler, $object); + if ($circularReferenceHandler = $this->circularReferenceHandler) { + return $circularReferenceHandler($object); } throw new CircularReferenceException(sprintf('A circular reference has been detected (configured limit: %d).', $this->circularReferenceLimit)); @@ -164,7 +164,7 @@ public function normalize($object, $format = null, array $context = array()) $attributeValue = $method->invoke($object); if (array_key_exists($attributeName, $this->callbacks)) { - $attributeValue = call_user_func($this->callbacks[$attributeName], $attributeValue); + $attributeValue = $this->callbacks[$attributeName]($attributeValue); } if (null !== $attributeValue && !is_scalar($attributeValue)) { if (!$this->serializer instanceof NormalizerInterface) { diff --git a/src/Symfony/Component/Serializer/Normalizer/PropertyNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/PropertyNormalizer.php index 428af1a9dccd5..a46d3015c08da 100644 --- a/src/Symfony/Component/Serializer/Normalizer/PropertyNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/PropertyNormalizer.php @@ -97,7 +97,7 @@ public function normalize($object, $format = null, array $context = array()) $attributeValue = $property->getValue($object); if (array_key_exists($property->name, $this->callbacks)) { - $attributeValue = call_user_func($this->callbacks[$property->name], $attributeValue); + $attributeValue = $this->callbacks[$property->name]($attributeValue); } if (null !== $attributeValue && !is_scalar($attributeValue)) { $attributeValue = $this->serializer->normalize($attributeValue, $format); diff --git a/src/Symfony/Component/Templating/PhpEngine.php b/src/Symfony/Component/Templating/PhpEngine.php index 6cc26a318432d..a16258b77e1d9 100644 --- a/src/Symfony/Component/Templating/PhpEngine.php +++ b/src/Symfony/Component/Templating/PhpEngine.php @@ -340,17 +340,19 @@ public function escape($value, $context = 'html') return $value; } + $escaper = $this->getEscaper($context); + // If we deal with a scalar value, we can cache the result to increase // the performance when the same value is escaped multiple times (e.g. loops) if (is_scalar($value)) { if (!isset(self::$escaperCache[$context][$value])) { - self::$escaperCache[$context][$value] = call_user_func($this->getEscaper($context), $value); + self::$escaperCache[$context][$value] = $escaper($value); } return self::$escaperCache[$context][$value]; } - return call_user_func($this->getEscaper($context), $value); + return $escaper($value); } /** diff --git a/src/Symfony/Component/Translation/PluralizationRules.php b/src/Symfony/Component/Translation/PluralizationRules.php index 221be605d9052..d4c22d98ed785 100644 --- a/src/Symfony/Component/Translation/PluralizationRules.php +++ b/src/Symfony/Component/Translation/PluralizationRules.php @@ -40,7 +40,7 @@ public static function get($number, $locale) } if (isset(self::$rules[$locale])) { - $return = call_user_func(self::$rules[$locale], $number); + $return = self::$rules[$locale]($number); if (!is_int($return) || $return < 0) { return 0; diff --git a/src/Symfony/Component/Validator/Constraints/CallbackValidator.php b/src/Symfony/Component/Validator/Constraints/CallbackValidator.php index a6a29e7e6e337..ebec2fbb3c8e3 100644 --- a/src/Symfony/Component/Validator/Constraints/CallbackValidator.php +++ b/src/Symfony/Component/Validator/Constraints/CallbackValidator.php @@ -55,7 +55,7 @@ public function validate($object, Constraint $constraint) throw new ConstraintDefinitionException(sprintf('"%s::%s" targeted by Callback constraint is not a valid callable', $method[0], $method[1])); } - call_user_func($method, $object, $this->context); + $method($object, $this->context); continue; } diff --git a/src/Symfony/Component/Validator/Constraints/ChoiceValidator.php b/src/Symfony/Component/Validator/Constraints/ChoiceValidator.php index 1566c318c3def..3b65a3f6ceafc 100644 --- a/src/Symfony/Component/Validator/Constraints/ChoiceValidator.php +++ b/src/Symfony/Component/Validator/Constraints/ChoiceValidator.php @@ -49,13 +49,12 @@ public function validate($value, Constraint $constraint) } if ($constraint->callback) { - if (is_callable(array($this->context->getClassName(), $constraint->callback))) { - $choices = call_user_func(array($this->context->getClassName(), $constraint->callback)); - } elseif (is_callable($constraint->callback)) { - $choices = call_user_func($constraint->callback); - } else { + if (!is_callable($choices = array($this->context->getClassName(), $constraint->callback)) + || !is_callable($choices = $constraint->callback) + ) { throw new ConstraintDefinitionException('The Choice constraint expects a valid callback'); } + $choices = $choices(); } else { $choices = $constraint->choices; } diff --git a/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php b/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php index 240f925b6c067..3de5fad667c0a 100644 --- a/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php +++ b/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php @@ -257,7 +257,7 @@ protected function castResource(Stub $stub, $isNested) private function callCaster($callback, $obj, $a, $stub, $isNested) { try { - $cast = call_user_func($callback, $obj, $a, $stub, $isNested); + $cast = $callback($obj, $a, $stub, $isNested); if (is_array($cast)) { $a = $cast; @@ -281,8 +281,8 @@ public function handleError($type, $msg, $file, $line, $context) throw new \ErrorException($msg, 0, $type, $file, $line); } - if ($this->prevErrorHandler) { - return call_user_func($this->prevErrorHandler, $type, $msg, $file, $line, $context); + if ($eh = $this->prevErrorHandler) { + return $eh($type, $msg, $file, $line, $context); } return false; diff --git a/src/Symfony/Component/VarDumper/Dumper/AbstractDumper.php b/src/Symfony/Component/VarDumper/Dumper/AbstractDumper.php index bc793499acf45..1170f269c4f56 100644 --- a/src/Symfony/Component/VarDumper/Dumper/AbstractDumper.php +++ b/src/Symfony/Component/VarDumper/Dumper/AbstractDumper.php @@ -115,7 +115,8 @@ public function dump(Data $data, $output = null) */ protected function dumpLine($depth) { - call_user_func($this->lineDumper, $this->line, $depth, $this->indentPad); + $lineDumper = $this->lineDumper; + $lineDumper($this->line, $depth, $this->indentPad); $this->line = ''; } diff --git a/src/Symfony/Component/VarDumper/VarDumper.php b/src/Symfony/Component/VarDumper/VarDumper.php index c728439df21bd..ab775806dd396 100644 --- a/src/Symfony/Component/VarDumper/VarDumper.php +++ b/src/Symfony/Component/VarDumper/VarDumper.php @@ -27,15 +27,15 @@ class VarDumper public static function dump($var) { - if (null === self::$handler) { + if (null === $h = self::$handler) { $cloner = new VarCloner(); $dumper = 'cli' === PHP_SAPI ? new CliDumper() : new HtmlDumper(); - self::$handler = function ($var) use ($cloner, $dumper) { + $h = self::$handler = function ($var) use ($cloner, $dumper) { $dumper->dump($cloner->cloneVar($var)); }; } - return call_user_func(self::$handler, $var); + return $h($var); } public static function setHandler($callable)