Commit ce6698a
committed
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
-------
473653d [Core] Fix cycle() with non-countable ArrayAccess+Traversable objects2 files changed
+42
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
417 | 417 | | |
418 | 418 | | |
419 | 419 | | |
420 | | - | |
| 420 | + | |
421 | 421 | | |
422 | | - | |
423 | | - | |
424 | 422 | | |
425 | 423 | | |
426 | 424 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| 35 | + | |
| 36 | + | |
34 | 37 | | |
35 | 38 | | |
36 | 39 | | |
| |||
407 | 410 | | |
408 | 411 | | |
409 | 412 | | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
410 | 451 | | |
411 | 452 | | |
412 | 453 | | |
| |||
0 commit comments