class::method() : réorthographié comme array ?
Je cherche en vain dans le manuel php, l'explication de la syntaxe que j'ai rencontrée plusieurs fois pour une method dans un argument : exemple
register_shutdown_function(array(&$this, "shutdown"));
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| <?php
class destruction {
var $name;
function __construct($name) {
$this->name = $name;
register_shutdown_function(array(&$this, "shutdown"));
}
function shutdown() {
echo 'shutdown: '.$this->name."\n";
}
function __destruct() {
echo 'destruct: '.$this->name."\n";
}
}
$a = new destruction('a: global 1');
function test() {
$b = new destruction('b: func 1');
$c = new destruction('c: func 2');
}
test();
$d = new destruction('d: global 2');
?>
this will output:
shutdown: a: global 1
shutdown: b: func 1
shutdown: c: func 2
shutdown: d: global 2
destruct: b: func 1
destruct: c: func 2
destruct: d: global 2
destruct: a: global 1
?> |
Si je remplace l'argument (array($this, "shutdown")) par (destruction::shutdown()), le code ne renvoie aucune erreur.
S'agirait-il donc d'une syntaxe alternative, (array($this, "method")) ou (class::method()) ?
Savez vous sous quelle rubrique je pourrais trouver l'explication de cette syntaxe?
Merci pour votre aide.