From:             
Operating system: Linux / ubuntu
PHP version:      5.3.10
Package:          SimpleXML related
Bug Type:         Bug
Bug description:asXML function returns string that cannot be casted as integer

Description:
------------
---
>From manual page: http://www.php.net/simplexmlelement.asxml
---

I have array of arrays like
$result = array();
foreach ($wholesalers as $wholesaler) {
   $result[] = array("Saldo" => $wholesaler->Available->asXML());
}

Available tag contains numeric value (integer) that should now be in
string

This simplexml generated string cannot by typecasted to integer


Test script:
---------------
funtion SortSaldos($array1, $array2) {
        $saldo1 = $array1['Saldo'];
        $saldo2 = $array2['Saldo'];

        echo "type: " . gettype($saldo1) . " $saldo1 as int " .
intval($saldo1) . " vs $saldo2 " . gettype($saldo2) . " as int " .
intval($saldo2) . "<br>";
        echo "petri debug $saldo1 < $saldo2";
        $saldo1 = intval($saldo1);
        $saldo2 = intval($saldo2);
        if ($saldo1 === $saldo2) {
            echo " equal<br>";
            return 0;
        }
        if ($saldo1 < $saldo2) {
            echo " -1 <br>";
            return -1;
        } else {
            echo " 1 <br>";
            return 1;
        }
}

uasort($result, "SortSaldos");


and with the function I see my debug information on screen:
type: string 1 as int 0 vs 2 string as int 0
petri debug 1 < 2 equal
type: string 9 as int 0 vs 1 string as int 0
petri debug 9 < 1 equal
type: string 1 as int 0 vs 4 string as int 0
petri debug 1 < 4 equal

so intval is always failing for strings generated by simplexml->asXML -
function.

If I do my saldo with typecasting like this:
$result = array();
foreach ($wholesalers as $wholesaler) {
   $result[] = array("Saldo" => (string) $wholesaler->Available);
}

everything works like expected


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

Reply via email to