mirror of
https://github.com/php/php-src.git
synced 2024-09-21 09:57:23 +00:00
Make $generator->send() return the current value
This makes the API easier to use (and is consistent with Python and JS).
This commit is contained in:
parent
ee89e228f6
commit
1477be9aa8
20
Zend/tests/generators/send_returns_current.phpt
Normal file
20
Zend/tests/generators/send_returns_current.phpt
Normal file
@ -0,0 +1,20 @@
|
||||
--TEST--
|
||||
$generator->send() returns the yielded value
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
function *reverseEchoGenerator() {
|
||||
$data = yield;
|
||||
while (true) {
|
||||
$data = yield strrev($data);
|
||||
}
|
||||
}
|
||||
|
||||
$gen = reverseEchoGenerator();
|
||||
var_dump($gen->send('foo'));
|
||||
var_dump($gen->send('bar'));
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
string(3) "oof"
|
||||
string(3) "rab"
|
@ -336,7 +336,7 @@ ZEND_METHOD(Generator, next)
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto void Generator::send()
|
||||
/* {{{ proto mixed Generator::send()
|
||||
* Sends a value to the generator */
|
||||
ZEND_METHOD(Generator, send)
|
||||
{
|
||||
@ -366,6 +366,10 @@ ZEND_METHOD(Generator, send)
|
||||
generator->send_target->var.ptr_ptr = &value;
|
||||
|
||||
zend_generator_resume(object, generator TSRMLS_CC);
|
||||
|
||||
if (generator->value) {
|
||||
RETURN_ZVAL(generator->value, 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/* {{{ proto void Generator::close()
|
||||
|
Loading…
Reference in New Issue
Block a user