From:             
Operating system: CentOS 5
PHP version:      5.3.2
Package:          *General Issues
Bug Type:         Bug
Bug description:XMLReader cannot store values in arrays

Description:
------------
I have tried every way possible to store the values from an XML sheet using
XMLReader in an array. The XML sheet is valid. I have tried this on two
systems now, both with the same problem. Colleagues cannot find anything
wrong either. Example code is below:



CODE:



$reader = new XMLReader();

$url = 'http://xml.com/info.php'; // not a real URL

        

$reader->open($url);

        

$i = 0;

$j = 0;

        

while ($reader->read())

{

        if ($reader->nodeType == XMLReader::ELEMENT)

        {

                $attr[$i] = $reader->getAttribute("name"); // does not store 
anything

                $attr .= $reader->getAttribute("name"); // stores
perfectly

                i++;

        }

        if ($reader->nodeType == XMLReader::TEXT)

        {

                $val[$j] = $reader->value; // performs the same as above

                $val .= $reader->value;

                $j++;

        }

}

Test script:
---------------
$reader = new XMLReader();

$url = 'http://xml.com/info.php'; // insert a real URL to test

        

$reader->open($url);

        

$i = 0;

        

while ($reader->read())

{       

        if ($reader->nodeType == XMLReader::TEXT)

        {

                $val[$i] = $reader->value; // does not work

                //$val .= $reader->value; // for demonstration only, works 
properly

                $i++;

        }

}



print_r($val);

Expected result:
----------------
When using a valid URL and XML sheet, "print_r" should print an array of
all values stored.

Actual result:
--------------
Instead, the entire array is empty. As soon as you use .= instead of
storing in an array, everything is printed fine simply using "echo".

-- 
Edit bug report at http://bugs.php.net/bug.php?id=51837&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=51837&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=51837&r=trysnapshot53
Try a snapshot (PHP 6.0):            
http://bugs.php.net/fix.php?id=51837&r=trysnapshot60
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=51837&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=51837&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=51837&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=51837&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=51837&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=51837&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=51837&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=51837&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=51837&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=51837&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=51837&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=51837&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=51837&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=51837&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=51837&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=51837&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=51837&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=51837&r=mysqlcfg

Reply via email to