PHP, ¿qué es esto? (parece una llamada a una función de objeto usando un nombre de función dinámica)

I want to find a explanation for this code including the name used for it and any offical documentation, but I cant find much on it,

 <?php $objects = $this->module->{'GetObjects'.ucfirst($key).'Array'}(); ?>

It seems to be calling a object function using dynamic value. Any documentation on this or tutorials or information?

gracias

preguntado el 09 de marzo de 12 a las 16:03

I always wanted to find a good use for variable variables.... I'm still searching. -

2 Respuestas

It's called 'variable variables'. check this link: http://php.net/manual/en/language.variables.variable.php

respondido 09 mar '12, 16:03

When u need to call dynamic methods, you need to put your variable between { }, like in the questions´s example ...

If you are dealing with ordninaries variable, you could use only $$ like:

$var1 = 1;
$var2 = 2;
$var4 = 3;
$var4 = 4;
for ($i = 1; $i < 5; $i++) {

$aux = 'var'.$i;
echo $$aux

}

This above code shpuld print: 1234

respondido 09 mar '12, 18:03

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.