7
I’m trying to use the magic method __call
and the function call_user_func_array
to recover the method name to be able to upload a file. I am doing it as follows
//Classe que importa os objetos
$obj = 'NovoObjeto';
$metodo = 'importarXML';
$objCriado = new $obj();
$objCriado->$metodo();
Each object of mine extends from a class called FullObject
and in that class I have the following statement of the magical method:
//FullObject
function __call($name,$arguments = null) {
if(method_exists($this, $name)) {
$this->method = $name;
return call_user_func_array(array($this,$name),$arguments);
} else {
throw new Exception('erro');
}
}
//Classo NovoObjeto
class NovoObjeto extends FullObject {
function importarXML() { ... }
}
The problem that happens is that if there is no method, it launches a Exception
, but if there is the method it does not pass the method name to the property $this->method
.
And I need to save this name, because I will be using it elsewhere, but I want to avoid having to pass it always as a parameter.
"I’m trying to use the magic method __calle the call_user_func_array function to retrieve the method name to load a file." - It was not clear what you want to do, could explain better what you want?
– gmsantos