How to pass more than one argument to variable functions in php

0
class Alumno{
    function mostrar($nombre,$edad){
        echo "la edad es $edad, nombre: $nombre";
    }
}

$clase="Alumno";
$func="mostrar";
$arg="juan,23";
$x=new $clase;
$x->$func($arg);

I only get one argument to the function. I also tried with call_user_func_xxxx but it comes with array , etc .. Someone who has done something of this?
The idea is to create objects in a dynamic way.

    
asked by salazarwalter 25.07.2018 в 22:38
source

2 answers

0

What happens is that you are just passing an argument, in which you separate it with a (,) but still remains one ...

class Alumno{
    function mostrar($nombre,$edad){
        echo "la edad es $edad, nombre: $nombre";
    }
}

$clase="Alumno";
$func="mostrar";
$arg1="juan,23";
$arg2="23";
$x=new $clase;
$x->$func($arg1, $arg2);

Look, so, when you declare that a function carries two arguments, in the call you also pass the two arguments separated by (,) ... I hope it serves you ... By: JJ

    
answered by 25.07.2018 в 22:44
0

Error mine:

call_user_func_array(array($objeto,$action_name),$valores);

The argument $valores was wrong, it wrote array($valores) , when $valores was already an array .

    
answered by 25.07.2018 в 22:44