Skip to content

Fix GH-21583: SimpleXML empty element incorrectly casts to true.#21590

Closed
devnexen wants to merge 1 commit intophp:PHP-8.4from
devnexen:gh21583
Closed

Fix GH-21583: SimpleXML empty element incorrectly casts to true.#21590
devnexen wants to merge 1 commit intophp:PHP-8.4from
devnexen:gh21583

Conversation

@devnexen
Copy link
Copy Markdown
Member

No description provided.

@ndossche
Copy link
Copy Markdown
Member

This changes very long standing behaviour. The current behaviour is here since PHP 5.1.x. PHP 5.0.x had different behaviour, closer to what you propose in the PR but not quite the same.
Since this is changing such old behaviour this can only go into master.
I'm also not so sure whether this should be fixed in the code or if this is a documentation mistake. The new code makes more sense than what it was because now it is similar to a string cast followed by a bool cast.
It raises the question though why the current behaviour is what it is.

@devnexen
Copy link
Copy Markdown
Member Author

devnexen commented Apr 2, 2026

This changes very long standing behaviour. The current behaviour is here since PHP 5.1.x. PHP 5.0.x had different behaviour, closer to what you propose in the PR but not quite the same. Since this is changing such old behaviour this can only go into master. I'm also not so sure whether this should be fixed in the code or if this is a documentation mistake.

If that helps, I would rather go towards doc fix.

@iluuu1994
Copy link
Copy Markdown
Member

I agree. While peculiar, this doesn't look like accidental behavior. Changing might be ok, but not in a patch.

I'd also add that I think falsy objects are questionable, though I understand that's nothing new in this PR.

@Girgias
Copy link
Copy Markdown
Member

Girgias commented Apr 2, 2026

I agree. While peculiar, this doesn't look like accidental behavior. Changing might be ok, but not in a patch.

I'd also add that I think falsy objects are questionable, though I understand that's nothing new in this PR.

Especially because the SimpleXML behaviour is prone to be quite buggy. I wonder if we should deprecate this feature for SimpleXML.

@ndossche
Copy link
Copy Markdown
Member

ndossche commented Apr 2, 2026

Just change the docs to the sample that casting a new GMP(0) instance results in false or something like that. It's intuitive enough and requires less words than currently.

@devnexen devnexen closed this Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SimpleXML: empty child element without attributes casts to true instead of false

4 participants