Eventuali duplicati:
Calling closure assigned to object property directlyPHP allegata alla stdObject e incatenato
Se ho una classe come questa:
class test{
function one(){
$this->two()->func(); //Since $test is returned, why can I not call func()?
}
function two(){
$test = (object) array();
$test->func = function(){
echo 'Does this work?';
};
return $test;
}
}
$new = new test;
$new->one(); //Expecting 'Does this work?'
Quindi la mia domanda è, quando Chiaro la funzione due dalla funzione uno, la funzione due restituisce la variabile $ test che ha una funzione di chiusura di func() ad essa allegata. Perché non posso chiamarlo come metodo concatenato?
Edit ho appena ricordato che questo può anche essere fatto utilizzando $ this-> func -> __ richiamare() per chiunque che ha bisogno di questo.
Heh, interessante. Grazie per l'aiuto. –