note 14105 modified in function.call-user-func by vrana

From: Date: Tue, 17 Aug 2004 14:53:48 +0000
Subject: note 14105 modified in function.call-user-func by vrana
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-79894@lists.php.net to get a copy of this message
I was trying to call multiple functions within a class, and after a brain frying experience this is what came out... hope it helps: <?php class Foo { function hey1($id){echo "In hey1";} function hey2($id){echo "In hey2";} #... and so forth ... function runtest($id) { #the fun part :) for($i=1; $i<=2; $i++) { $fp = "hey".$i; $this->$fp($id); } } } ?> It worked like a charm :). --was-- I was trying to call multiple functions within a class, and after a brain frying experience this is what came out... hope it helps: class Foo { function hey1($id){echo "In hey1";} function hey2($id){echo "In hey2";} #... and so forth ... function runtest($id) { #the fun part :) for($i=1; $i<=2; $i++) { $fp = "hey".$i; $this->$fp($id); } } } It worked like a charm :). http://php.net/manual/en/function.call-user-func.php

« previous php.notes (#79894) next »