Unfortunately, the xml_set_object function does not work to solve this
problem. I tried using it, and my results were the same as they were when I
was not using it. 

[I found that the array($this, 'function_name') method instead of 'string
function_name' for the xml_set_*_handler functions worked just as well, only
without this Warning message one gets from PHP 4.2.1 upon using
xml_set_object($this->parser, &$this):

"PHP Warning:  Call-time pass-by-reference has been deprecated - argument
passed by value;  If you would like to pass it by reference, modify the
declaration of xml_set_object().  If you would like to enable call-time
pass-by-reference, you can set allow_call_time_pass_reference to true in
your INI file.  However, future versions may not support this any longer."]


Still searching for an answer on this one ...

Thanks,
-Clay



> "Peter Clarke" <[EMAIL PROTECTED]>
>
> Have a look at:
> http://www.php.net/manual/en/function.xml-set-object.php
> 
> xml_set_object($this->parser, &$this);
> 
>
> 
> "Clay Loveless" <[EMAIL PROTECTED]> wrote in message
> [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
>> Here's a brain-bender ... At least it is for me at the moment. : )
>> 
>> When I use an XML parser inside a class, the xml_*_handler functions
> aren't
>> recognizing "$this->" variables. I can kind of see why ... But would like
> it
>> to work anyway. : )
>> 
>> Here's an example:
>> 
>> class Blah
>> {
>>     var $xmlparser;
>>     var $current_element;
>> 
>>     // ...
>> 
>>     function _parseXML($data)
>>     {
>>         $this->xmlparser = xml_parser_create();
>>         xml_set_element_handler(
>>             $this->xmlparser,
>>             array($this,"_xml_start_element"),
>>             array($this,"_xml_end_element"));
>>         xml_set_character_data_handler(
>>             $this->xmlparser,
>>             array($this,"_xml_character_data"));
>>         xml_parse($this->xmlparser, $data);
>>         xml_parser_free($this->xmlparser);
>>     }
>> 
>>     function _xml_start_element($p, $e_name, $e_attributes)
>>     {
>>             $this->current_element = $e_name;
>>     }
>> 
>>     function _xml_end_element($p, $e_name)
>>     {
>>             // ...
>>     }
>> 
>>     function _xml_character_data($p, $data)
>>     {
>>         echo "element is: ".$this->current_element."\n";
>>         echo "data is: $data\n";
>>     }
>> 
>> } // end of class Blah
>> 
>> 
>> 
>> When this XML parser gets called from within the Blah class, the "element
>> is:" portion of _xml_character_data comes out blank!
>> 
>> This sort of makes sense, because the callback functions are "children" of
>> the xml_parser_create "parent" ... But should that make the children
>> ignorant of the "grandparent" variables referred to by $this->varname?
>> 
>> I hope this makes sense ... Has anyone else encountered this sort of
>> problem? I'm an old hat at PHP, but am relatively new to both XML parsing
>> and writing my own classes.
>> 
>> Thanks,
>> Clay
>> 
> 
> 


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

Reply via email to