Bug->Req #72957 [Opn]: Null coalescing operator doesn't behave as expected with SimpleXMLElement
| From: | requinix@php.net | Date: | Sun, 28 Aug 2016 20:14:57 +0000 |
| Subject: | Bug->Req #72957 [Opn]: Null coalescing operator doesn't behave as expected with SimpleXMLElement | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-203634@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=72957&edit=1
ID: 72957
Updated by: requinix@php.net
Reported by: dailywatchdeal at gmail dot com
Summary: Null coalescing operator doesn't behave as expected
with SimpleXMLElement
Status: Open
-Type: Bug
+Type: Feature/Change Request
Package: SimpleXML related
Operating System: Ubuntu
PHP Version: 7.0.10
Block user comment: N
Private report: N
New Comment:
That's because $xml->elem2 exists and isn't null. isset works differently.
Previous Comments:
------------------------------------------------------------------------
[2016-08-28 18:42:20] dailywatchdeal at gmail dot com
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 this bug report at https://bugs.php.net/bug.php?id=72957&edit=1