I'm trying to use the magic method __call
and the call_user_func_array
function to retrieve the method name to be able to load a file. I'm doing it this way
//Classe que importa os objetos
$obj = 'NovoObjeto';
$metodo = 'importarXML';
$objCriado = new $obj();
$objCriado->$metodo();
Each object of my extends from a class called FullObject
and in this class I have the following declaration of the magic 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 the method does not exist, it throws a Exception
, but if the method exists it does not pass the method name to the property $this->method
.
I need to save this name, because I'll be using it elsewhere, but I want to avoid having to be forced to always pass it as a parameter.