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

SimpleXML xpath should warn when returning other return types than node lists #12231

Closed
nielsdos opened this issue Sep 17, 2023 · 1 comment
Closed

Comments

@nielsdos
Copy link
Member

Description

Currently, the xpath method only returns node lists. So for example, functions like count(), boolean(), string(), ... don't work.
Very simple (and silly) example:

<?php

$xml = "<container><foo/><foo/></container>";
$sxe = simplexml_load_string($xml);

var_dump($sxe->xpath("count(//foo)"));
var_dump(count($sxe->xpath("//foo")));

3v4l: https://3v4l.org/nmD4k

I expect the output to be twice int(2), instead the output from xpath is an empty array.
Either we should have an additional method for arbitrary xpath evaluations (like in the case of DOM), or the xpath method should be changed to auto-detect the return type of the query. Both are feasibly, but the last one could be a BC break because of the return type change.

@nielsdos nielsdos changed the title SimpleXML xpath allow other types of return than node lists SimpleXML xpath should allow other return types than node lists Sep 17, 2023
@nielsdos nielsdos changed the title SimpleXML xpath should allow other return types than node lists SimpleXML xpath should warn when returning other return types than node lists Mar 15, 2025
@nielsdos
Copy link
Member Author

Changing the issue a bit to make the goal warning the user that the expression is wrong. Changing the actual return type may be a too big BC break.

nielsdos added a commit to nielsdos/php-src that referenced this issue Mar 15, 2025
nielsdos added a commit to nielsdos/php-src that referenced this issue Mar 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant