Skip to content

SplFixedArray corrupted #16160

@mvorisek

Description

@mvorisek

Description

I have investigated some weird behaviour and I came to a conclusion it must be an issue in php-src.

Steps to reproduce:

  1. clone https://github.com/mvorisek/PHP-CS-Fixer/tree/fix_tokens_cache_8228
  2. run composer update
  3. run php repro.php
  4. notice output "BUG DETECTED!!"

In the repro branch, there are 3 important files:

The last file/line is very interesting. How can foreach ($this as $t) {} have an effect on the result?

a) I know, the $t is kept allocated until out of scope, but that is not decisive here (tested)
b) the $this is a class that extends \SplFixedArray, but the getIterator() method is not extended (nor getSize(), count(), offsetGet()), so the foreach should have zero effect

The foreach ($this as $t) {} however fix the corruption! So I guess there is something wrong in php-src internally.

For unknown reasons, the "foreach fix" is working on PHP 7.4 only. I know PHP 7.4 is EOL, but can someone please reproduce the issue on PHP 7.4 and answer why foreach ($this as $t) {} is fixing the problem, ie. what internal/php-src side effects it does?

I guess with this question answered, it would be easy to understand this main issue even for higher/latest php version(s).

PHP Version

any

Operating System

any (tested Windows and linux)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions