Doc #79256 [Opn->Asn]: generator->next() not behaving as documented.

From: Date: Fri, 14 Feb 2020 13:35:21 +0000
Subject: Doc #79256 [Opn->Asn]: generator->next() not behaving as documented.
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-17301@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79256&edit=1 ID: 79256 Updated by: peehaa@php.net Reported by: selanefa at outlook dot com Summary: generator->next() not behaving as documented. -Status: Open +Status: Assigned Type: Documentation Problem Package: Unknown/Other Function Operating System: Ubuntu 18.04.3 PHP Version: 7.2.27 -Assigned To: +Assigned To: ekin Block user comment: N Private report: N Previous Comments: ------------------------------------------------------------------------ [2020-02-14 13:34:39] peehaa@php.net I agree with OP here. They are not exactly equivalent. Maybe just remove the description and at a note with something like: > calling Generator::send() will already advance so there is no need to manually call > Generator::next() ? ------------------------------------------------------------------------ [2020-02-13 17:41:26] ekin@php.net 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? ------------------------------------------------------------------------ [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

« previous php.doc.bugs (#17301) next »