summaryrefslogtreecommitdiff
path: root/Zend/zend_opcode.c
diff options
context:
space:
mode:
authorNikita Popov <nikic@php.net>2012-07-22 20:11:09 +0200
committerNikita Popov <nikic@php.net>2012-07-22 20:11:09 +0200
commit134089372b94de2e3e8c2a1aba4cbc415c803d67 (patch)
tree90fca0bc751801e6a63ab571e85097890882f137 /Zend/zend_opcode.c
parent94b2ccae9ce95c4c71bb8db8ce75dcdf26df7d7a (diff)
downloadphp-git-134089372b94de2e3e8c2a1aba4cbc415c803d67.tar.gz
Throw error also for return occuring before yield
Previously only an error was thrown when return occured after yield. Also returns before the first yield would fail for by-ref generators. Now the error message is handled in pass_two, so all returns are checked.
Diffstat (limited to 'Zend/zend_opcode.c')
-rw-r--r--Zend/zend_opcode.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/Zend/zend_opcode.c b/Zend/zend_opcode.c
index 65fa85185e..0042c37299 100644
--- a/Zend/zend_opcode.c
+++ b/Zend/zend_opcode.c
@@ -532,6 +532,18 @@ ZEND_API int pass_two(zend_op_array *op_array TSRMLS_DC)
case ZEND_JMP_SET_VAR:
opline->op2.jmp_addr = &op_array->opcodes[opline->op2.opline_num];
break;
+ case ZEND_RETURN:
+ case ZEND_RETURN_BY_REF:
+ if (op_array->fn_flags & ZEND_ACC_GENERATOR) {
+ if (opline->op1_type != IS_CONST || Z_TYPE_P(opline->op1.zv) != IS_NULL) {
+ CG(zend_lineno) = opline->lineno;
+ zend_error(E_COMPILE_ERROR, "Generators cannot return values using \"return\"");
+ }
+ if (opline->opcode == ZEND_RETURN_BY_REF) {
+ opline->opcode = ZEND_RETURN;
+ }
+ }
+ break;
}
ZEND_VM_SET_OPCODE_HANDLER(opline);
opline++;