Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use PHP 5.6 variadic function arguments with Symfony 2.8?

Tags:

php

symfony

I have service method with variadic arguments:

public function callSP($namespace, $function, ...$params) {}

which is compiled into container like :

public function callSP($namespace, $function, $params = null)

so it causes :

Strict Standards notice saying that callSP() should be compatible with XXX\XXX\Service::callSP($namespace, $function, ...$params)

Can't find even any questions about that.

like image 1000
Virginijus Maila Avatar asked Apr 28 '16 07:04

Virginijus Maila


People also ask

How do you use variadic arguments?

In C programming, a variadic function adds flexibility to the program. It takes one fixed argument and then any number of arguments can be passed. The variadic function consists of at least one fixed variable and then an ellipsis(…) as the last parameter. This enables access to variadic function arguments.

How will you passing an argument to a function in PHP?

PHP Function ArgumentsArguments are specified after the function name, inside the parentheses. You can add as many arguments as you want, just separate them with a comma.

What is variadic function PHP?

A variadic function accepts a variable number of parameters. The following example defines a function called sum() that returns the sum of two integers: <? php function sum(int $x, int $y) { return $x + $y; } echo sum(10, 20); // 30. Code language: PHP (php)

Is printf variadic function?

Variadic functions are functions (e.g. printf) which take a variable number of arguments. The declaration of a variadic function uses an ellipsis as the last parameter, e.g. int printf(const char* format, ...);.


1 Answers

I suppose, that problem occures for some kind of lazy service (listener, or explicit lazy: true)

Lazy services are operated with ocramius/proxy-manager library.

This library introduced support for variadic parameters since version 2.0, which requires at least PHP 7.0.

So I think there is nothing to do with 5.6 here.

Links:

  • https://symfony.com/doc/current/service_container/lazy_services.html
  • https://github.com/Ocramius/ProxyManager/releases/tag/2.0.0
  • https://github.com/Ocramius/ProxyManager/issues/307
like image 191
ScayTrase Avatar answered Oct 11 '22 10:10

ScayTrase