0
I have the class y:
class y {
private $group = [];
public function __construct(){
$this->group['Start'] = array(
'GET' => array(
'Home' => array(
'Method' => 'ControllerHome@index',
'Logged' => true,
'Parameters' => false
)
)
);
}
public function GET($g, $function, $logged, $parameters){
$explode = explode('/', $g);
if(array_key_exists($explode[0], $this->group)){
if(!array_key_exists($explode[1], $this->group[$explode[0]]['GET'])){
$this->group[$explode[0]]['GET'][$explode[1]] = array(
'Method' => $function,
'Logged' => $logged,
'Parameters' => $parameters
);
//var_dump($this->group);
$t = new z('a');
return $t;
}
} else {
$this->group[$explode[0]]['GET'] = [];
$this->GET($g, $function, $logged, $parameters);
}
}
public function POST($g, $function, $logged, $parameters){
$explode = explode('/', $g);
if(array_key_exists($explode[0], $this->group)){
if(!array_key_exists($explode[1], $this->group[$explode[0]]['GET'])){
$this->group[$g]['GET'][$explode[1]] = array(
'Method' => $function,
'Logged' => $logged,
'Parameters' => $parameters
);
var_dump($this->group);
}
} else {
$this->group[$explode[0]] = [];
$this->x($g, $function, $logged, $parameters);
}
}
}
Just below I have the class z:
class z {
public function __construct($teste){
}
public function r($mensagem){
return $mensagem;
}
}
What I want is to call the function of the other class - in case r()
.
$a = new y();
$a->GET('k/home', 'ControllerHome@index', true, false)->r('teste');
Is there a specific name for this action? How can I use it? Because I’m getting the error below?
Error: Call to a member function r() on null in C:\laragon\www\nota_veio_novo\index.php on line 70
In his job
GET
add the return:retur $this->GET($g, $function, $logged, $parameters);
– Costamilam
William, thank you for answering, but it hasn’t worked yet..
– Joao Pedro
I think you can work as follows:https://answall.com/questions/16769/usar-function
– Elton Silva
Thanks for answering Elton, I just wanted to understand how it works the way I showed on top... but I’ll take a look there, thanks!!
– Joao Pedro
@Joaopedro, Probably the code is falling on
else
(of the methodGET
), returns nothing. By default, the PHP considers this value as null. That’s why the mistake.– Valdeir Psr