Skip to content

Instantly share code, notes, and snippets.

View athrawes's full-sized avatar

Andrew Moyes athrawes

  • Brno, CZ
View GitHub Profile
@athrawes
athrawes / isEmptyIssue.php
Last active October 11, 2023 15:05
Demonstrates an issue with `\iter\isEmpty()` for objects implementing `\IteratorAggregate` where `getIterator()` is impure
<?php
/**
* Copied directly from https://github.com/nikic/iter/blob/master/src/iter.php#L1090
* on commit d9f88bc
*/
function isEmpty($iterable): bool {
if (\is_array($iterable) || $iterable instanceof \Countable) {
return count($iterable) == 0;
}