Callback function as parameter

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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,

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux