Callback function as parameter
| From: | Francisco M. Marzoa Alonso | Date: | Wed, 10 Nov 2004 18:17:09 +0000 |
| Subject: | Callback function as parameter | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-201704@lists.php.net to get a copy of this message | ||
Hi everybody,
I want to wrote a function that receives another function as parameter that will be used as a Callback. Well, better a bit of code than thousand words:
class TreeNode {
...
function Traverse ( CallBack ) {
$rtn = CallBack ($this);
foreach ($this->Sons as $Son) {
$Son->Traverse ( CallBack );
}
return $rtn;
}
...
}
And later I'll do something as:
function CallBack ( $Node ) {
echo $Node->Name;
}
$MyTreeNode->Traverse ( CallBack );
...
Hope you understand what I'm trying to do. Can it be done as is or am I on the wrong way?
Thx. a million in advance,