Doc #79256 [Com]: generator->next() not behaving as documented.
Edit report at https://bugs.php.net/bug.php?id=79256&edit=1
ID: 79256
Comment by: ekin@php.net
Reported by: selanefa at outlook dot com
Summary: generator->next() not behaving as documented.
Status: Open
Type: Documentation Problem
Package: Unknown/Other Function
Operating System: Ubuntu 18.04.3
PHP Version: 7.2.27
Block user comment: N
Private report: N
New Comment:
Hi, I see your point, though the signature documented should make it obvious that Generator::next()
will not return a value:
public Generator::next ( void ) : void
Is it confusing enough to need clarification, knowing the signature mentions the return type?
Previous Comments:
------------------------------------------------------------------------
[2020-02-11 10:39:11] selanefa at outlook dot com
Description:
------------
---
From manual page: https://php.net/generator.next
---
The documentation states:
Calling Generator::next() is equivalent to calling Generator::send() with NULL as argument.
However, calling Generator::send(null) moves the pointer and returns the current value, while
Generator::next() only moves the pointer and returns nothing.
Test script:
---------------
function generateCountdown(int $start) {
while ($start>=0) {
yield $start--;
}
}
$gen = generateCountdown(3);
echo $gen->current().PHP_EOL;
echo $gen->send(null).PHP_EOL;
echo $gen->send(null).PHP_EOL;
$gen->next();
echo $gen->current().PHP_EOL;
Expected result:
----------------
3
2
1
0
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79256&edit=1
Thread (7 messages)