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

From: Date: Fri, 14 Feb 2020 13:34:39 +0000
Subject: Doc #79256 [Opn]: generator->next() not behaving as documented.
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-17300@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
 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:

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()

?


Previous Comments:
------------------------------------------------------------------------
[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


Thread (7 messages)

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