Re: Callback functions inside classes - how to?

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

 



From the manual:

http://uk.php.net/manual/en/language.pseudo-types.php#language.types.callback

If you want to change things in the callback, the function (or method) should accept its parameters by reference.

e.g.

class A
{
 function name(&$a, $b, $c)
 {
   $a = $b . $c;
   return;
 }

 function parse()
 {
   // whatever
   // then (calls $this->name())
   $parser->set_handler( "root/page/title", array($this, 'name') );
   // or (calls A::name())
   $parser->set_handler( "root/page/title", array('A', 'name') );
   // more whatever
 }

}

Hope this helps

Cheers

Chris

Thomas Hochstetter wrote:

Hi again,

I have always been wondering how this is done properly:

Here is an example:

[snip]
class A {
  function name( $a, $b, $c) {
     $tmp = array();
     $tmp[a] = $a;
     .
    array_push( $GLOBALS['XMLStack'], $tmp );
 }

 function parse() {
   .. some definitions .
   $parser->set_handler( "root/page/title", "name" );
  . some more stuff here .
 }
}
[/snip]

What I want is to have the callback function name as it is in the above
example. But, obviously, the above code won't work. So, how do I tell the
set_handler function that it must use the name function from the class?
Using:
"A::name" or "$this->name" (if instantiated) . how do these callback
function calls work, because the same issue is with the xml handler
functions in php4 (have not as yet been to v5).

Also, how can I get the data from the callback function out without using
$GLOBALS? I cannot just return an array, can I?

Any ideas.

Thanks so  long.

Thomas



-- 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