Bug #76382 [NEW]: There's no way to override conversion to Boolean, yet SimpleXMLElement does it

From: Date: Sun, 27 May 2018 16:50:29 +0000
Subject: Bug #76382 [NEW]: There's no way to override conversion to Boolean, yet SimpleXMLElement does it
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-215389@lists.php.net to get a copy of this message
From: teo8976 at gmail dot com Operating system: PHP version: 7.2.6 Package: *General Issues Bug Type: Bug Bug description:There's no way to override conversion to Boolean, yet SimpleXMLElement does it Description: ------------ --- From manual page: http://php.net/manual/en/language.types.boolean.php#language.types.boolean.casting --- """""""" When converting to boolean, the following values are considered FALSE: the boolean FALSE itself the integer 0 (zero) the float 0.0 (zero) the empty string, and the string "0" an array with zero elements the special type NULL (including unset variables) SimpleXML objects created from empty tags <<<<<<<<<<<<< THIS!!!! Every other value is considered TRUE (including any resource and NAN). """""""" The SimpleXML class is "magical" in that it overrides the general rule that any non-null object evaluates to true, and it has its own way of converting to boolean. Yet there's no (documented and non-hacky) way a user-defined class can do the same and define its own rules to convert to boolean. There's no __toBoolean() (like there is a __toString()) magic method, and there's no operator overloading for overloading the == operator. This is DISGUSTING. That a built-in class can do some magic that no user-defined class can do, is a symptom of an incredibly poor language design. The very moment you decided that non-null SimpleXML objects should evaluate to false in certain cases, you should have realized that any user-defined class could need to do the same thing, and you should have provided a generic mechanism of doing that, rather than hard-coding some magic into a particular built-in class. -- Edit bug report at https://bugs.php.net/bug.php?id=76382&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=76382&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=76382&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=76382&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=76382&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=76382&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=76382&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=76382&r=needscript Try newer version: https://bugs.php.net/fix.php?id=76382&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=76382&r=support Expected behavior: https://bugs.php.net/fix.php?id=76382&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=76382&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=76382&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=76382&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=76382&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=76382&r=dst IIS Stability: https://bugs.php.net/fix.php?id=76382&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=76382&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=76382&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=76382&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=76382&r=mysqlcfg

« previous php.bugs (#215389) next »