note 41087 modified in function.call-user-func by danbrown

From: Date: Sat, 19 Jul 2008 21:13:17 +0000
Subject: note 41087 modified in function.call-user-func by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-141746@lists.php.net to get a copy of this message
Some of the wierder examples below confused me, and made me think that the following would work (but it does!). <?php class barber{ function shop($one,$two,$three,$four='quartet'){ echo $one.','.$two.','.$three.','.$four; } } $bsq = new barber; call_user_func(array(&$bsq,'shop'),'one','two','three'); /* Output = one,two,three,quartet */ class bigBarber{ var $quartet; function bigBarber(){ $this->quartet = 'four'; } function shop($one,$two,$three,$five='quintet'){ echo $one.','.$two.','.$three.','.$this->quartet.','.$five; } } $bbsq = new bigBarber(); call_user_func(array(&$bbsq,'shop'),'one','two','three'); /* Output = one,two,three,four,quintet */ ?> --was-- Some of the wierder examples below confused me, and made me think that the following would work (but it does!). <? class barber{ function shop($one,$two,$three,$four='quartet'){ echo $one.','.$two.','.$three.','.$four; } } $bsq = new barber; call_user_func(array(&$bsq,'shop'),'one','two','three'); /* Output = one,two,three,quartet */ class bigBarber{ var $quartet; function bigBarber(){ $this->quartet = 'four'; } function shop($one,$two,$three,$five='quintet'){ echo $one.','.$two.','.$three.','.$this->quartet.','.$five; } } $bbsq = new bigBarber(); call_user_func(array(&$bbsq,'shop'),'one','two','three'); /* Output = one,two,three,four,quintet */ ?> http://php.net/manual/en/function.call-user-func.php

« previous php.notes (#141746) next »