SimpleXML: empty child element without attributes casts to true instead of false
Aperta
Bug
Extension: simplexml
Status: Verified
- Lingua principale
- C
- Stelle
- 40.4k
- Fork
- 8.1k
- Merge medio
- 2g 13h
- PR unite (30g)
- 96
Descrizione
The following code:
<?php
$cases = [
'<foo><bar>content</bar></foo>',
'<foo><bar/></foo>',
'<foo/>',
];
foreach ($cases as $case) {
\printf("%-30s: %s\n", $case, new \SimpleXMLElement($case)->bar ? '✅' : '❌');
}
Resulted in this output:
<foo><bar>content</bar></foo> : ✅
<foo><bar/></foo> : ✅
<foo/> : ❌
But I expected this output instead:
<foo><bar>content</bar></foo> : ✅
<foo><bar/></foo> : ❌
<foo/> : ❌
The documentation explicitly lists empty SimpleXML elements without attributes as falsy.
https://www.php.net/manual/en/language.types.boolean.php#language.types.boolean.casting
PHP Version
any
Operating System
Debian 13
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Valutazione
Questa issue non è ancora stata valutata.