note 40865 added to ref.xml
| From: | mowlux at rn2 dot php dot net | Date: | Wed, 17 Mar 2004 14:36:11 +0000 |
| Subject: | note 40865 added to ref.xml | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-66959@lists.php.net to get a copy of this message | ||
I ve spotted a strange behaviour with this class :
class xml_reader{
var $entity_stack;
var $test;
function xml_reader(){
$this->entity_stack=array();
$this->test=0;
}
function create_array_entity($name){
$nb=count($this->entity_stack);
print "$this->test $nb-e_start : \"$name\"<br>";
$this->test++;
array_push($this->entity_stack,$name);
//print_r($this->entity_stack);
print "$this<br>";
}
function get_array_entity($name){
$this->test--;
array_pop($this->entity_stack);
$nb=count($this->entity_stack);
print "$this->test $nb-e_end : \"$name\"<br>";
//print_r($this->entity_stack);
print "$this<br>";
}
function elementStart($parser, $name, $attrs){
$this->create_array_entity($name);
}
function elementEnd($parser, $name){
$this->get_array_entity($name);
}
function read_file($filename){
$xml_parser = xml_parser_create();
$start_handler_func=array($this,"elementStart");
$end_handler_func=array($this,"elementEnd");
xml_set_element_handler($xml_parser
,$start_handler_func
,$end_handler_func);
if (!($fp = fopen($filename, "r"))) {
die("Impossible d'ouvrir le fichier XML");
}
while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("erreur XML : %s à la ligne %d"
,xml_error_string(xml_get_error_code($xml_parser))
,xml_get_current_line_number($xml_parser)));
}
}
xml_parser_free($xml_parser);
}
}
The problem is that theses lines
(using the array syntax for handling
functions) seems to duplicate or
something the object, because
the object vars ($entity_stack and $test)
are different references in the function
calls of the parser.
(Modification of a value in one A function
isn't accessible in the other B function,
but remain in A when called again...)
$start_handler_func=array($this,"elementStart");
$end_handler_func=array($this,"elementEnd");
xml_set_element_handler($xml_parser
,$start_handler_func
,$end_handler_func);
----
Manual Page -- http://www.php.net/manual/en/ref.xml.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+40865
Delete -- http://master.php.net/manage/user-notes.php?action=delete+40865&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+40865&report=yes
Search -- http://master.php.net/manage/user-notes.php