Voting

: min(one, one)?
(Example: nine)

The Note You're Voting On

wizzard351 at yahoo dot com
3 years ago
One important thing to remember is that in iterator can be infinite. Not all iterators necessarily end. If iterator_to_array is used on such an iterator, it will exhaust the available memory, and throw a fatal error.

For example, consider the following code:

<?php

function fibonacci(): Generator
{
yield
$a = 1;
yield
$b = 2;

start:
yield
$c = $a + $b;
$a = $b;
$b = $c;
goto
start;
}

$fibonacciSequence = fibonacci();
iterator_to_array($fibonacciSequence);

?>

Since <?php fibonacci(); ?> generates an infinite fibonacci sequence, which is valid, since it is actually an infinite sequence, then attempting to convert it to an array will fail.

<< Back to user notes page

To Top