Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove weird object creation in SimpleXML #5252

Closed
wants to merge 1 commit into from

Conversation

nikic
Copy link
Member

@nikic nikic commented Mar 10, 2020

Currently SXE optimizes for maximum WTF per minute:

$xml = new SimpleXMLElement('<root><elem>Text</elem></root>');
var_dump(isset($xml->doesNotExist)); // bool(false)
var_dump($xml->doesNotExist); // object(SimpleXMLElement)
var_dump($xml->doesNotExist->alsoDoesntExist); // null

There was a partial fix in https://bugs.php.net/bug.php?id=72957 to at least treat this correctly in BP_VAR_IS mode.

I think we should make use of the chance in PHP 8, and stop returning a dummy object if the node does not exist:

$xml = new SimpleXMLElement('<root><elem>Text</elem></root>');
var_dump(isset($xml->doesNotExist)); // bool(false)
var_dump($xml->doesNotExist); // null
var_dump($xml->doesNotExist->alsoDoesntExist); // null + warning

However, I'm not entirely clear on whether this is a small or a large BC break. Any thoughts?

@nikic
Copy link
Member Author

nikic commented May 11, 2020

Based on discussion in chat (with @cmb69 @beberlei maybe? It's been a while) I think the consensus was that SimpleXML has a lot of weird behavior that people rely on in even weirder ways, and it's probably not worth trying to change anything about it... Going to close this one.

@nikic nikic closed this May 11, 2020
@cmb69
Copy link
Contributor

cmb69 commented May 11, 2020

Unfortunately, I have to agree. Before doing actual improvements to SimpleXML, the desired behavior would need to be specified exactly. Any volunteers?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants