note 52226 added to ref.xml

From: Date: Mon, 25 Apr 2005 07:23:45 +0000
Subject: note 52226 added to ref.xml
Groups: php.notes 
Request: Send a blank email to php-notes+get-88514@lists.php.net to get a copy of this message
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 ++; } ---- Manual Page -- http://www.php.net/manual/en/ref.xml.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+52226 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52226&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52226&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52226&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52226&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52226&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+52226&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#88514) next »