ID: 30972 Updated by: [EMAIL PROTECTED] Reported By: dtorop932 at gmail dot com -Status: Open +Status: Bogus Bug Type: SimpleXML related Operating System: GNU/Linux 2.4.27 PHP Version: 5CVS-2004-12-03 (dev) New Comment:
Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php Use ===, !== or is_null Previous Comments: ------------------------------------------------------------------------ [2004-12-03 05:47:46] dtorop932 at gmail dot com Description: ------------ According to http://www.php.net/manual/en/language.types.boolean.php it seems that in PHP 5 all objects should return TRUE when cast to boolean. But if one creates a SimpleXML object from the string '<goodxml/>', then casts it to boolean, the result is FALSE. As a comparison, running DOMDocument::loadxml() on "<goodxml/>" and casting the result to boolean returns TRUE. This is important if one is doing what seems to be a quick test for failure of SimpleXML parsing, e.g. the following doesn't work as expected: if (!simplexml_load_string($anyxml)) { return FALSE; // this always executes, even for good XML } Reproduce code: --------------- <?php foreach (array('badxml', '<goodxml/>', '<goodxml>CONTENT</goodxml>') as $xml) { $dom = @simplexml_load_string($xml); print "\n\$dom from '$xml'\n"; print ' ((boolean) $dom) = '; var_dump((boolean) $dom); } ?> Expected result: ---------------- $dom from 'badxml' ((boolean) $dom) = bool(false) $dom from '<goodxml/>' ((boolean) $dom) = bool(true) $dom from '<goodxml>CONTENT</goodxml>' ((boolean) $dom) = bool(true) Actual result: -------------- $dom from 'badxml' ((boolean) $dom) = bool(false) $dom from '<goodxml/>' ((boolean) $dom) = bool(false) $dom from '<goodxml>CONTENT</goodxml>' ((boolean) $dom) = bool(true) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=30972&edit=1
