[go: up one dir, main page]

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 infinite loop when a cast is used inside a foreach #12208

Closed
nielsdos opened this issue Sep 13, 2023 · 0 comments
Closed

SimpleXML infinite loop when a cast is used inside a foreach #12208

nielsdos opened this issue Sep 13, 2023 · 0 comments

Comments

@nielsdos
Copy link
Member
nielsdos commented Sep 13, 2023

Description

The following code:

<?php

$xml = "<root><a>1</a><a>2</a></root>";
$xml = simplexml_load_string($xml);

$a = $xml->a;

foreach ($a as $test) {
    var_dump((string) $a->current());
    var_dump((string) $a);
}

Resulted in this output:
an infinite loop

But I expected this output instead:

string(1) "1"
string(1) "1"
string(1) "2"
string(1) "1"

I think at least, because $a always refers to the first element implicitly, and only current points to the current iterated-over item?

This is basically the same as #12192, but triggered in a different yet similar way.

PHP Version

PHP 8.1+

Operating System

Linux

nielsdos added a commit to nielsdos/php-src that referenced this issue Sep 17, 2023
nielsdos added a commit that referenced this issue Sep 17, 2023
* PHP-8.1:
  Fix GH-12208: SimpleXML infinite loop when a cast is used inside a foreach
nielsdos added a commit that referenced this issue Sep 17, 2023
* PHP-8.2:
  Fix GH-12208: SimpleXML infinite loop when a cast is used inside a foreach
nielsdos added a commit that referenced this issue Sep 17, 2023
* PHP-8.3:
  Fix GH-12208: SimpleXML infinite loop when a cast is used inside a foreach
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant