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

Remove all calls to call_user_func() #12520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Remove all calls to call_user_func()
  • Loading branch information
nicolas-grekas committed Nov 21, 2014
commit fd266c7da93c10801a0b92c4d4b9fa31202c8c6f
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/Config/Util/XmlUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions 4 src/Symfony/Component/Console/Command/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/Console/Helper/DialogHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ private function validateAttempts($interviewer, OutputInterface $output, $valida
}

try {
return call_user_func($validator, $interviewer());
return $validator($interviewer());
} catch (\Exception $error) {
}
}
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/Console/Helper/ProcessHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/Console/Helper/ProgressBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion 3 src/Symfony/Component/Console/Helper/QuestionHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}
}
Expand Down
10 changes: 5 additions & 5 deletions 10 src/Symfony/Component/CssSelector/XPath/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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));
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions 5 src/Symfony/Component/Debug/DebugClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions 4 src/Symfony/Component/Debug/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions 4 src/Symfony/Component/Debug/ExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ class RealServiceInstantiator implements InstantiatorInterface
*/
public function instantiateProxy(ContainerInterface $container, Definition $definition, $id, $realInstantiator)
{
return call_user_func($realInstantiator);
return $realInstantiator();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct(ContainerBuilder $container)
*/
public function load($resource, $type = null)
{
call_user_func($resource, $this->container);
$resource($this->container);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/EventDispatcher/EventDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
8 changes: 6 additions & 2 deletions 8 src/Symfony/Component/Form/CallbackTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions 5 src/Symfony/Component/HttpFoundation/JsonResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});

Expand Down
4 changes: 2 additions & 2 deletions 4 src/Symfony/Component/HttpFoundation/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't self::$requestFactory(... work here without creating an extra local variable ?


if (!$request instanceof Request) {
throw new \LogicException('The Request factory must return an instance of Symfony\Component\HttpFoundation\Request.');
Expand Down
4 changes: 2 additions & 2 deletions 4 src/Symfony/Component/HttpFoundation/StreamedResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion 3 src/Symfony/Component/Process/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,7 @@ protected function buildCallback($callback)
}

if (null !== $callback) {
call_user_func($callback, $type, $data);
$callback($type, $data);
}
};

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions 6 src/Symfony/Component/Templating/PhpEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/Translation/PluralizationRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.