From: wb at pro-net dot co dot uk
Operating system: FreeBSD, WindowsXP
PHP version: 5.0.0b4 (beta4)
PHP Bug Type: *XML functions
Bug description: SimpleXML Object forgetting values.
Description:
------------
When using simpleXML you are unable to fetch some information. The
information is displayed with print_r() but you can't get it it directly.
Use the example provided as an example.
Reproduce code:
---------------
<?php
header('Content-type: text/plain');
$xmlstr = '<?xml version="1.0"?>
<access>
<user>
<login>user1</login>
<password>letMeIn</password>
<site>www.pro-net.co.uk</site>
<site>www.example.com</site>
</user>
<user>
<login>user2</login>
<password>myPassword</password>
<site>www.pro-net.co.uk</site>
</user>
</access>';
$nl = "\r\n";
$xml = simplexml_load_string($xmlstr);
print('Current PHP version is : '.phpversion().$nl.$nl);
print('$xml is:'.$nl);
print_r($xml);
print($nl.$nl);
// Test authentication to get the correct user information
$login = 'user1';
$password = 'letMeIn';
print($nl.$nl.'Trying to authenticate "'.$login.'" with password
"'.$password.'".'.$nl.$nl);
$isAuth = false;
foreach($xml->user as $user){
if(utf8_decode($user->login) == $login && utf8_decode($user->password)
== $password){
$isAuth = true;
break;
}
}
if(!$isAuth){
print($nl.$nl.'Invalid User.'.$nl);
die();
}
// So lets output the variables to see what we have...
print('$user is:'.$nl);
print_r($user);
print($nl.$nl);
print('$user->site is:'.$nl);
print_r($user->site);
print($nl.$nl);
print('$user->site[0] is:'.$nl);
print_r($user->site[0]);
print($nl.$nl);
?>
Expected result:
----------------
$xml is:
simplexml_element Object
(
[user] => Array
(
[0] => simplexml_element Object
(
[login] => user1
[password] => letMeIn
[site] => Array
(
[0] => www.pro-net.co.uk
[1] => www.example.com
)
)
[1] => simplexml_element Object
(
[login] => user2
[password] => myPassword
[site] => www.pro-net.co.uk
)
)
)
Trying to authenticate "user1" with password "letMeIn".
$user is:
simplexml_element Object
(
[login] => user1
[password] => letMeIn
[site] => Array
(
[0] => www.pro-net.co.uk
[1] => www.example.com
)
)
$user->site is:
Array
(
[0] => www.pro-net.co.uk
[1] => www.example.com
)
$user->site[0] is:
www.pro-net.co.uk
Actual result:
--------------
$xml is:
simplexml_element Object
(
[user] => Array
(
[0] => simplexml_element Object
(
[login] => user1
[password] => letMeIn
[site] => Array
(
[0] => www.pro-net.co.uk
[1] => www.example.com
)
)
[1] => simplexml_element Object
(
[login] => user2
[password] => myPassword
[site] => www.pro-net.co.uk
)
)
)
Trying to authenticate "user1" with password "letMeIn".
$user is:
simplexml_element Object
(
[login] => user1
[password] => letMeIn
[site] => Array
(
[0] => www.pro-net.co.uk
[1] => www.example.com
)
)
$user->site is:
Array
(
[0] => simplexml_element Object
(
)
[1] => simplexml_element Object
(
)
)
$user->site[0] is:
simplexml_element Object
(
)
--
Edit bug report at http://bugs.php.net/?id=27418&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=27418&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=27418&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=27418&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=27418&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=27418&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=27418&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=27418&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=27418&r=support
Expected behavior: http://bugs.php.net/fix.php?id=27418&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=27418&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=27418&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=27418&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=27418&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=27418&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=27418&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=27418&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=27418&r=float