From:             
Operating system: 
PHP version:      5.3SVN-2010-07-27 (SVN)
Package:          SimpleXML related
Bug Type:         Bug
Bug description:spl_object_hash() has strange behaviors with SimpleXML

Description:
------------
Hey :-),



spl_object_hash() has strange behaviors with SimpleXML.

You know that SimpleXMLElement uses properties to access to its children
collection and array-access to reach a specific child into this
collection.

So, if we want to reach an element, we have to do: $sxe->element[0] for
example. Unfortunately, it appears to always return a “new object”
according to spl_object_hash(). Please, see the code below.



You can notice that $sxe->p has sometimes the same has than $sxe-p[0]. And
why $sxe-p[0] has most of the time a different hash?

Test script:
---------------
<?php



$xml = '<?xml version="1.0" encoding="utf-8"?>' . "\n\n" .

       '<page>' . "\n" .

       '  <p>Foobar</p>' . "\n" .

       '</page>';





$sxe = simplexml_load_string($xml);



function f ( $e ) {



    return spl_object_hash($e);

}



var_dump(f($sxe->p));

var_dump(f($sxe->p));

var_dump(f($sxe->p[0]));

var_dump(f($sxe->p[0]));

var_dump(f($sxe->p[0]));

var_dump(f($sxe->p[0]));

var_dump(f($sxe->p[0]));

var_dump(f($sxe->p[0]));



echo "\n" . 'Light!' . "\n\n";



function g ( $e ) {



    return substr(f($e), 14, 2);

}



var_dump(g($sxe->p));

var_dump(g($sxe->p));

var_dump(g($sxe->p[0]));

var_dump(g($sxe->p[0]));

var_dump(g($sxe->p[0]));

var_dump(g($sxe->p[0]));

var_dump(g($sxe->p[0]));

var_dump(g($sxe->p[0]));

Expected result:
----------------
string(32) "000000005cddd92f000000002401191e"

string(32) "000000005cddd92f000000002401191e"

string(32) "000000005cddd929000000002401191e"

string(32) "000000005cddd929000000002401191e"

string(32) "000000005cddd929000000002401191e"

string(32) "000000005cddd929000000002401191e"

string(32) "000000005cddd929000000002401191e"

string(32) "000000005cddd929000000002401191e"



Light!



string(2) "2f"

string(2) "2f"

string(2) "29"

string(2) "29"

string(2) "29"

string(2) "29"

string(2) "29"

string(2) "29"

Actual result:
--------------
string(32) "000000005cddd92f000000002401191e"

string(32) "000000005cddd92f000000002401191e"

string(32) "000000005cddd929000000002401191e"

string(32) "000000005cddd92e000000002401191e"

string(32) "000000005cddd92f000000002401191e"

string(32) "000000005cddd929000000002401191e"

string(32) "000000005cddd92e000000002401191e"

string(32) "000000005cddd92f000000002401191e"



Light!



string(2) "2f" // p

string(2) "2f" // p, same hash, oof

string(2) "29" // p[0], ok

string(2) "2e" // p[0], huh?

string(2) "2f" // p[0], has the hash that p… why?

string(2) "29" // p[0], like the first p[0]

string(2) "2e" // p[0], we have a loop here

string(2) "2f" // p[0], definitively, we have a loop.

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

Reply via email to