note 107474 deleted from function.simplexml-load-string by tularis
| From: | tularis@php.net | Date: | Sun, 12 Feb 2012 11:40:58 +0000 |
| Subject: | note 107474 deleted from function.simplexml-load-string by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-186086@lists.php.net to get a copy of this message | ||
Note Submitter: rahj8786 at yahoo dot com
----
when using an simplexml_load_string and getting an ID and equate it with an integer does not return
TRUE, hence the ID is still an OBJECT. Type casting an Object ID will also remove leading zeros and
therefore cannot equate with the Object ID reference and return to FALSE. for Example:
<?php
/**
* @author reynaldoahipolito
* @copyright 2012
*/
$response_xml = "this is the reponse xml";
$xml = simplexml_load_string($response_xml);
//ex: xml response for ID == 0012345
if ($xml->attributes()->id == 0012345) {
//will return FALSE;
}
//if we typecast it to integer
$id = (int) $xml->attributes()->id;
if ($id == 0012345) {
//will still return false, hence PHP will removed leading zero when casting it into integer.
}
if ($id == 12345) {
//will return to true since PHP already remove the leading zeros of the ID when casting it.
}
//heres how to solve it. just make the Object ID into string. the Object ID will equate to ID
string.
if ($xml->attributes()->id == '0012345') {
// will return to TRUE.
}
?>