-
-
Notifications
You must be signed in to change notification settings - Fork 324
Document limitations when using lazy loaded dependencies that involve variadic functions #359
Copy link
Copy link
Closed
Labels
Milestone
Description
When using lazy loaded dependencies, I encountered some curious behaviour when handing over more parameters to a function than defined in its signature (variadic functions).
class Service
{
/**
* @param mixed $param1
* @param mixed $param2
* @param mixed $paramN Can be used to supply additional parameters
*/
public function doStuf($param1, $param2){
echo func_num_args();
}
}Now let's try to use this Service when fetched from the dependency injection container
$dic->get('Service')->doStuff(1, 2, 3); //Prints '3' when not lazy loaded
$dic->get('Service')->doStuff(1, 2, 3); //Prints '2' when lazy loadedI use this approach to inject extra variables when translating messages like: "User X has logged in on Y", where X and Y would be 'additional' parameters.
This probably has to do with the intermediate proxy classes that are generated. For example from a generated proxy class:
/**
* {@inheritDoc}
*/
public function doStuf($param1, $param2)
{
$this->initializer5683c4a86687a054344119 && $this->initializer5683c4a86687a054344119->__invoke($this->valueHolder5683c4a866860700867865, $this, 'fireEventOnOrder', array('param1' => $param1, 'param2' => $param2), $this->initializer5683c4a86687a054344119);
return $this->valueHolder5683c4a866860700867865->fireEventOnOrder($param1, $param2);
}When looking at Ocramius/ProxyManager#177, I think this behaviour is expected. Therefore I think it should be mentioned in the documentation as a warning...
Reactions are currently unavailable