Fabien Potencier ce6698abd5 bug #4713 Fix cycle() with non-countable ArrayAccess+Traversable objects (yoeunes)
This PR was merged into the 3.x branch.

Discussion
----------

Fix cycle() with non-countable ArrayAccess+Traversable objects

When using `cycle()` with an object that implements `\ArrayAccess` and `\Traversable` but is not `\Countable`, the function currently returns the object instance immediately after triggering the deprecation notice.

This prevents the value from being converted to an array, causing the cycle logic to fail or return the object itself.

This PR removes the early return to ensure `self::toArray()` is called, allowing these objects to be cycled correctly as expected.

**How to test**

```php
$seq = new class implements \ArrayAccess, \IteratorAggregate {
    public function offsetExists($offset): bool { return true; }
    public function offsetGet($offset): mixed { return 'val'; }
    public function offsetSet($offset, $value): void {}
    public function offsetUnset($offset): void {}
    public function getIterator(): \Traversable { yield 'odd'; yield 'even'; }
};

// Should return 'odd', currently returns the $seq object
$result = CoreExtension::cycle($seq, 0);
```

Related to #4241

Commits
-------

473653d19b [Core] Fix cycle() with non-countable ArrayAccess+Traversable objects
2025-11-25 07:55:14 +01:00
2025-07-29 09:57:34 +02:00
2025-07-29 10:07:07 +02:00
2025-07-29 10:07:07 +02:00
2025-11-16 17:02:42 +01:00
2025-01-31 21:45:36 +01:00
2024-11-20 20:05:33 +01:00
2024-09-03 10:17:14 +02:00

Twig, the flexible, fast, and secure template language for PHP
==============================================================

Twig is a template language for PHP.

Twig uses a syntax similar to the Django and Jinja template languages which
inspired the Twig runtime environment.

Sponsors
--------

.. raw:: html

    <a href="https://docs.blackfire.io/introduction?utm_source=twig&utm_medium=github_readme&utm_campaign=logo">
        <img src="https://static.blackfire.io/assets/intemporals/logo/png/blackfire-io_secondary_horizontal_transparent.png?1" width="255px" alt="Blackfire.io">
    </a>

More Information
----------------

Read the `documentation`_ for more information.

.. _documentation: https://twig.symfony.com/documentation
Languages
PHP 99.9%