Bug #72957 [NEW]: Null coalescing operator doesn't behave as expected with SimpleXMLElement

From: Date: Sun, 28 Aug 2016 18:42:21 +0000
Subject: Bug #72957 [NEW]: Null coalescing operator doesn't behave as expected with SimpleXMLElement
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-203632@lists.php.net to get a copy of this message
From: dailywatchdeal at gmail dot com Operating system: Ubuntu PHP version: 7.0.10 Package: SimpleXML related Bug Type: Bug Bug description:Null coalescing operator doesn't behave as expected with SimpleXMLElement Description: ------------ According to the docs, the ?? operator checks if the 1st operand exists and is not null. In other words, it's equivalent to isset. When used to check if a SimpleXMLElement node exists, it doesn't work. Test script: --------------- <?php $xml = new SimpleXMLElement('<root><elem>Text</elem></root>'); echo 'elem2 is: ' . ($xml->elem2 ?? 'backup string'); echo 'elem2 is: ' . (isset($xml->elem2) ? $xml->elem2 : 'backup string'); Expected result: ---------------- elem2 is: backup string elem2 is: backup string Actual result: -------------- elem2 is: elem2 is: backup string -- Edit bug report at https://bugs.php.net/bug.php?id=72957&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=72957&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=72957&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=72957&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=72957&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=72957&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=72957&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=72957&r=needscript Try newer version: https://bugs.php.net/fix.php?id=72957&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=72957&r=support Expected behavior: https://bugs.php.net/fix.php?id=72957&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=72957&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=72957&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=72957&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72957&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=72957&r=dst IIS Stability: https://bugs.php.net/fix.php?id=72957&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=72957&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=72957&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=72957&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=72957&r=mysqlcfg

« previous php.bugs (#203632) next »