|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #79126 empty() documentation does not mention SimpleXML objects from empty tags
Submitted: 2020-01-15 19:28 UTC Modified: -
Avg. Score:4.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: dse at webonastick dot com Assigned:
Status: Open Package: SimpleXML related
PHP Version: 7.4.1 OS: macOS
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: dse at webonastick dot com
New email:
PHP Version: OS:


 [2020-01-15 19:28 UTC] dse at webonastick dot com
From manual page:

<> mentions that for the following values, empty() will return TRUE:

- an unset variable
- ""
- 0
- 0.0
- "0"
- array()

The documentation does not mention that a SimpleXML object from an empty tag is also considered empty, thus empty() also returns TRUE for one.

I figured this out after checking <> while writing something for a PHP cheatsheet.

Test script:
$ php -r '$foo = new SimpleXMLElement("<html>5</html>"); print $foo ? "truthy\n" : "falsy\n";'

$ php -r '$foo = new SimpleXMLElement("<html></html>"); print $foo ? "truthy\n" : "falsy\n";'


Add a Patch

Pull Requests

Add a Pull Request

PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Sep 30 03:01:24 2020 UTC