Bug #81443 [NEW]: Inconsistent casting to bool of SimpleXML objects

From: Date: Wed, 15 Sep 2021 21:42:46 +0000
Subject: Bug #81443 [NEW]: Inconsistent casting to bool of SimpleXML objects
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-236634@lists.php.net to get a copy of this message
From: rk at srsbiz dot pl Operating system: * PHP version: Irrelevant Package: SimpleXML related Bug Type: Bug Bug description:Inconsistent casting to bool of SimpleXML objects Description: ------------ As documentation says https://www.php.net/manual/en/language.types.boolean.php#language.types.boolean.casting > SimpleXML objects created from attributeless empty elements are considered false, but in some cases such nodes are evaluated as true https://3v4l.org/qIH4a Not sure if this is SimpleXML or documentation problem Test script: --------------- <?php var_dump( (bool)simplexml_load_string('<root />'), (bool)simplexml_load_string('<root><branch /></root>')->branch, (bool)simplexml_load_string('<root><branch></branch></root>')->branch, (bool)simplexml_load_string('<root><otherbranch /><branch /></root>')->branch, (bool)simplexml_load_string('<root><branch /><branch /></root>')->branch[0], (bool)simplexml_load_string('<root><branch /><branch></branch></root>')->branch[1], ); Expected result: ---------------- bool(false) bool(false) bool(false) bool(false) bool(false) bool(false) Actual result: -------------- bool(false) bool(true) bool(true) bool(true) bool(false) bool(false) -- Edit bug report at https://bugs.php.net/bug.php?id=81443&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=81443&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=81443&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=81443&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=81443&r=needscript Try newer version: https://bugs.php.net/fix.php?id=81443&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=81443&r=support Expected behavior: https://bugs.php.net/fix.php?id=81443&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=81443&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=81443&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=81443&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=81443&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=81443&r=dst IIS Stability: https://bugs.php.net/fix.php?id=81443&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=81443&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=81443&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=81443&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=81443&r=mysqlcfg

« previous php.bugs (#236634) next »