PROJET AUTOBLOG


Shaarli - Les discussions de Shaarli

Archivé

Site original : Shaarli - Les discussions de Shaarli du 23/07/2013

⇐ retour index

Don't use `empty` on SimpleXMLElement

samedi 12 juillet 2014 à 13:21
phyks, le 12/07/2014 à 13:21
Using `empty` to test wether a SimpleXMLElement is empty or not can return very strange results (returning true when it should obviously return false) for an unknown reason.

A solution would be to use
```
empty((string) SimpleXMLElement);
```
but that does not work in PHP < 5.5.


So the best solution I found is using `isset()`, and comparing the string casted SimpleXMLElement to "". I found other solutions using count also, which might be the more reliable ones.
(Permalink)