note 52226 deleted from ref.xml by bjori

From: Date: Mon, 09 Oct 2006 11:15:07 +0000
Subject: note 52226 deleted from ref.xml by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-118293@lists.php.net to get a copy of this message
Note Submitter: salloum_corp at yahoo dot com ---- An example FIX in XMLSimpleParser .. pille at hbr1 dot com contributed a very very useful parser +regenerator, however, there is a small problem when handling an array. When adding an object to an array using array_push function, a new copy of the object is created and stored in the array. Therefore, any change made to the original object will not be seen in the copy withing the array! $this->current needs to reference the object in the array! The only change needed is in replacing the following lines withing startElement function in the second if statement: array_push( $this->current->$tag, $obj ); $this->current =& $obj; Replace with: $num=array_push( $this->current->$tag, $obj ); $arrayref =& $this->current->$tag; $this->current =& $arrayref[$num-1]; and the function will be eventually: function startElement($parser, $tag, $attributeList) { if( is_object( $this->current->$tag ) ) { $obj = $this->current->$tag; $this->current->$tag = array(); array_push( $this->current->$tag, $obj ); } if( is_array( $this->current->$tag ) ) { $obj =& new stdClass; $obj->_PARENT =& $this->current; $obj->_ITEMS = 0; $num=array_push( $this->current->$tag, $obj ); $arrayref =& $this->current->$tag; $this->current =& $arrayref[$num-1]; } else { $this->current->$tag->_PARENT =& $this->current; $this->current =& $this->current->$tag; $this->current->_ITEMS = 0; } $this->current->_PARENT->_ITEMS ++; }

« previous php.notes (#118293) next »