Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added this extra test file but I am not sure if this needed since the return_from_by_ref_generator.phpt also tests the notice.

Yield without value in reference generator function should create notice
--FILE--
<?php

function &y()
{
yield null;
yield;
}
foreach (y() as &$y);

?>
--EXPECTF--
Notice: Only variable references should be yielded by reference in %s on line %d

Notice: Only variable references should be yielded by reference in %s on line %d
3 changes: 2 additions & 1 deletion Zend/tests/generators/return_from_by_ref_generator.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ function gen2() {
gen2()->next();

?>
--EXPECT--
--EXPECTF--
Notice: Only variable references should be yielded by reference in %s on line %d
int(42)
4 changes: 4 additions & 0 deletions Zend/zend_vm_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -8051,6 +8051,10 @@ ZEND_VM_HANDLER(160, ZEND_YIELD, CONST|TMP|VAR|CV|UNUSED, CONST|TMPVAR|CV|UNUSED
}
}
} else {
if (UNEXPECTED(EX(func)->op_array.fn_flags & ZEND_ACC_RETURN_REFERENCE)) {
zend_error(E_NOTICE, "Only variable references should be yielded by reference");
}

/* If no value was specified yield null */
ZVAL_NULL(&generator->value);
}
Expand Down
80 changes: 80 additions & 0 deletions Zend/zend_vm_execute.h
Original file line number Diff line number Diff line change
Expand Up @@ -7334,6 +7334,10 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_YIELD_SPEC_CONST_CONST_HANDLER
}
}
} else {
if (UNEXPECTED(EX(func)->op_array.fn_flags & ZEND_ACC_RETURN_REFERENCE)) {
zend_error(E_NOTICE, "Only variable references should be yielded by reference");
}

/* If no value was specified yield null */
ZVAL_NULL(&generator->value);
}
Expand Down Expand Up @@ -9433,6 +9437,10 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_YIELD_SPEC_CONST_TMPVAR_HANDLE
}
}
} else {
if (UNEXPECTED(EX(func)->op_array.fn_flags & ZEND_ACC_RETURN_REFERENCE)) {
zend_error(E_NOTICE, "Only variable references should be yielded by reference");
}

/* If no value was specified yield null */
ZVAL_NULL(&generator->value);
}
Expand Down Expand Up @@ -10308,6 +10316,10 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_YIELD_SPEC_CONST_UNUSED_HANDLE
}
}
} else {
if (UNEXPECTED(EX(func)->op_array.fn_flags & ZEND_ACC_RETURN_REFERENCE)) {
zend_error(E_NOTICE, "Only variable references should be yielded by reference");
}

/* If no value was specified yield null */
ZVAL_NULL(&generator->value);
}
Expand Down Expand Up @@ -11819,6 +11831,10 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_YIELD_SPEC_CONST_CV_HANDLER(ZE
}
}
} else {
if (UNEXPECTED(EX(func)->op_array.fn_flags & ZEND_ACC_RETURN_REFERENCE)) {
zend_error(E_NOTICE, "Only variable references should be yielded by reference");
}

/* If no value was specified yield null */
ZVAL_NULL(&generator->value);
}
Expand Down Expand Up @@ -19607,6 +19623,10 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_YIELD_SPEC_TMP_CONST_HANDLER(Z
}
}
} else {
if (UNEXPECTED(EX(func)->op_array.fn_flags & ZEND_ACC_RETURN_REFERENCE)) {
zend_error(E_NOTICE, "Only variable references should be yielded by reference");
}

/* If no value was specified yield null */
ZVAL_NULL(&generator->value);
}
Expand Down Expand Up @@ -20010,6 +20030,10 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_YIELD_SPEC_TMP_TMPVAR_HANDLER(
}
}
} else {
if (UNEXPECTED(EX(func)->op_array.fn_flags & ZEND_ACC_RETURN_REFERENCE)) {
zend_error(E_NOTICE, "Only variable references should be yielded by reference");
}

/* If no value was specified yield null */
ZVAL_NULL(&generator->value);
}
Expand Down Expand Up @@ -20470,6 +20494,10 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_YIELD_SPEC_TMP_UNUSED_HANDLER(
}
}
} else {
if (UNEXPECTED(EX(func)->op_array.fn_flags & ZEND_ACC_RETURN_REFERENCE)) {
zend_error(E_NOTICE, "Only variable references should be yielded by reference");
}

/* If no value was specified yield null */
ZVAL_NULL(&generator->value);
}
Expand Down Expand Up @@ -20869,6 +20897,10 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_YIELD_SPEC_TMP_CV_HANDLER(ZEND
}
}
} else {
if (UNEXPECTED(EX(func)->op_array.fn_flags & ZEND_ACC_RETURN_REFERENCE)) {
zend_error(E_NOTICE, "Only variable references should be yielded by reference");
}

/* If no value was specified yield null */
ZVAL_NULL(&generator->value);
}
Expand Down Expand Up @@ -24737,6 +24769,10 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_YIELD_SPEC_VAR_CONST_HANDLER(Z
}
}
} else {
if (UNEXPECTED(EX(func)->op_array.fn_flags & ZEND_ACC_RETURN_REFERENCE)) {
zend_error(E_NOTICE, "Only variable references should be yielded by reference");
}

/* If no value was specified yield null */
ZVAL_NULL(&generator->value);
}
Expand Down Expand Up @@ -26956,6 +26992,10 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_YIELD_SPEC_VAR_TMPVAR_HANDLER(
}
}
} else {
if (UNEXPECTED(EX(func)->op_array.fn_flags & ZEND_ACC_RETURN_REFERENCE)) {
zend_error(E_NOTICE, "Only variable references should be yielded by reference");
}

/* If no value was specified yield null */
ZVAL_NULL(&generator->value);
}
Expand Down Expand Up @@ -28802,6 +28842,10 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_YIELD_SPEC_VAR_UNUSED_HANDLER(
}
}
} else {
if (UNEXPECTED(EX(func)->op_array.fn_flags & ZEND_ACC_RETURN_REFERENCE)) {
zend_error(E_NOTICE, "Only variable references should be yielded by reference");
}

/* If no value was specified yield null */
ZVAL_NULL(&generator->value);
}
Expand Down Expand Up @@ -31138,6 +31182,10 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_YIELD_SPEC_VAR_CV_HANDLER(ZEND
}
}
} else {
if (UNEXPECTED(EX(func)->op_array.fn_flags & ZEND_ACC_RETURN_REFERENCE)) {
zend_error(E_NOTICE, "Only variable references should be yielded by reference");
}

/* If no value was specified yield null */
ZVAL_NULL(&generator->value);
}
Expand Down Expand Up @@ -33234,6 +33282,10 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_YIELD_SPEC_UNUSED_CONST_HANDLE
}
}
} else {
if (UNEXPECTED(EX(func)->op_array.fn_flags & ZEND_ACC_RETURN_REFERENCE)) {
zend_error(E_NOTICE, "Only variable references should be yielded by reference");
}

/* If no value was specified yield null */
ZVAL_NULL(&generator->value);
}
Expand Down Expand Up @@ -34982,6 +35034,10 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_YIELD_SPEC_UNUSED_TMPVAR_HANDL
}
}
} else {
if (UNEXPECTED(EX(func)->op_array.fn_flags & ZEND_ACC_RETURN_REFERENCE)) {
zend_error(E_NOTICE, "Only variable references should be yielded by reference");
}

/* If no value was specified yield null */
ZVAL_NULL(&generator->value);
}
Expand Down Expand Up @@ -35516,6 +35572,10 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_YIELD_SPEC_UNUSED_UNUSED_HANDL
}
}
} else {
if (UNEXPECTED(EX(func)->op_array.fn_flags & ZEND_ACC_RETURN_REFERENCE)) {
zend_error(E_NOTICE, "Only variable references should be yielded by reference");
}

/* If no value was specified yield null */
ZVAL_NULL(&generator->value);
}
Expand Down Expand Up @@ -37425,6 +37485,10 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_YIELD_SPEC_UNUSED_CV_HANDLER(Z
}
}
} else {
if (UNEXPECTED(EX(func)->op_array.fn_flags & ZEND_ACC_RETURN_REFERENCE)) {
zend_error(E_NOTICE, "Only variable references should be yielded by reference");
}

/* If no value was specified yield null */
ZVAL_NULL(&generator->value);
}
Expand Down Expand Up @@ -42593,6 +42657,10 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_YIELD_SPEC_CV_CONST_HANDLER(ZE
}
}
} else {
if (UNEXPECTED(EX(func)->op_array.fn_flags & ZEND_ACC_RETURN_REFERENCE)) {
zend_error(E_NOTICE, "Only variable references should be yielded by reference");
}

/* If no value was specified yield null */
ZVAL_NULL(&generator->value);
}
Expand Down Expand Up @@ -46064,6 +46132,10 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_YIELD_SPEC_CV_TMPVAR_HANDLER(Z
}
}
} else {
if (UNEXPECTED(EX(func)->op_array.fn_flags & ZEND_ACC_RETURN_REFERENCE)) {
zend_error(E_NOTICE, "Only variable references should be yielded by reference");
}

/* If no value was specified yield null */
ZVAL_NULL(&generator->value);
}
Expand Down Expand Up @@ -47809,6 +47881,10 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_YIELD_SPEC_CV_UNUSED_HANDLER(Z
}
}
} else {
if (UNEXPECTED(EX(func)->op_array.fn_flags & ZEND_ACC_RETURN_REFERENCE)) {
zend_error(E_NOTICE, "Only variable references should be yielded by reference");
}

/* If no value was specified yield null */
ZVAL_NULL(&generator->value);
}
Expand Down Expand Up @@ -51359,6 +51435,10 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_YIELD_SPEC_CV_CV_HANDLER(ZEND_
}
}
} else {
if (UNEXPECTED(EX(func)->op_array.fn_flags & ZEND_ACC_RETURN_REFERENCE)) {
zend_error(E_NOTICE, "Only variable references should be yielded by reference");
}

/* If no value was specified yield null */
ZVAL_NULL(&generator->value);
}
Expand Down
Loading