php.net |  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: -
Votes:1
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
Have you experienced this issue?
Rate the importance of this bug to you:

 [2020-01-15 19:28 UTC] dse at webonastick dot com
Description:
------------
---
From manual page: https://php.net/function.empty
---

<https://php.net/function.empty> mentions that for the following values, empty() will return TRUE:

- an unset variable
- ""
- 0
- 0.0
- "0"
- NULL
- FALSE
- 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 <https://www.php.net/manual/en/language.types.boolean.php> while writing something for a PHP cheatsheet.

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

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



Patches

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