RE: [PHP] callbacks to methods inside a class/object

From: Date: Tue, 17 Sep 2002 21:47:02 +0000
Subject: RE: [PHP] callbacks to methods inside a class/object
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-116664@lists.php.net to get a copy of this message
You can send an array that has the object and method name on some functions. Quote: "Instead of a function name, an array containing an object reference and a method name can also be supplied." (this quote is from array_filter()) I think the format is something like array_filter(array('object','method'),$array) It may depend on which function you are talking about, though... ---John Holmes... > -----Original Message----- > From: Douglas Marsh [mailto:marsh_douglas@hotmail.com] > Sent: Tuesday, September 17, 2002 5:16 PM > To: php-general@lists.php.net > Subject: [PHP] callbacks to methods inside a class/object > > > Is there a "clean" way to make use of PHP builtins that use callbacks and > point those call backs to a method inside the class/object: > > A good example would be: > > ... > > class XMLClass { > > var $parser; > > function XMLClass() { > $this->parser = xml_parser_create(); > xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, TRUE); > xml_set_element_handler($this->parser, "$this->start", "$this->end"); > xml_set_character_data_handler($this->parser, "$this->data"); > } > > function goodbye() { // a manual destructor > xml_parser_free($this->parser); > // other things possibly too > } > > > function start($p2, $name, $attr) { > // do things here > } > > function data($p2, $data) { > // do some more here > } > > function end($p2, $name) { > // do even more things here > } > > [... and so on ...] > > ... > > But since there is no way to set a callback to "$this->[function_name]" > one > must create a global function that uses a global object and passes things > to > the method inside the class.. > > Is the a way to address this? or perhaps a better way to deal with > callback > function names? > > --Douglas Marsh > > > > > > > _________________________________________________________________ > MSN Photos is the easiest way to share and print your photos: > http://photos.msn.com/support/worldwide.aspx > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#116664) next »