[php-src] Issue #19243: ArrayAccess and foreach

From: Date: Sat, 26 Jul 2025 09:07:18 +0000
Subject: [php-src] Issue #19243: ArrayAccess and foreach
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-250495@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/19243 Author: staabm ### Description the [docs describe foreach](https://www.php.net/manual/en/control-structures.foreach.php) as > The foreach construct provides an easy way to iterate over > [array](https://www.php.net/manual/en/language.types.array.php)s and > [Traversable](https://www.php.net/manual/en/class.traversable.php) objects. foreach will issue an > error when used with a variable containing a different data type or with an uninitialized variable. while working on [a PHPStan issue](https://github.com/phpstan/phpstan/issues/13270), I recently discovered that php also allows to iterate over an object implementing ArrayAccess, even though thats neither Traversable nor is_iterable nor is_array. see https://3v4l.org/ifJv7#veol --- I am a bit lost whether - this actually works like expected? - this needs a doc update? - whether I am overlooking something ### PHP Version ```plain any since PHP 7.1+ ``` ### Operating System macOS sequioa

« previous php.bugs (#250495) next »