Skip to content

Commit 3321440

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Fix return value of wrong fucntion by-ref assign
2 parents 53fba3a + 6617829 commit 3321440

File tree

4 files changed

+26
-24
lines changed

4 files changed

+26
-24
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
Return value of assigning by-val function result by-reference
3+
--FILE--
4+
<?php
5+
$a = [&$a];
6+
var_dump($a[0] =& returnsVal());
7+
function returnsVal() {}
8+
?>
9+
--EXPECTF--
10+
Notice: Only variables should be assigned by reference in %s on line %d
11+
NULL

Zend/zend_execute.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -560,18 +560,16 @@ static zend_never_inline zval* zend_assign_to_typed_property_reference(zend_prop
560560
return prop;
561561
}
562562

563-
static zend_never_inline ZEND_COLD bool zend_wrong_assign_to_variable_reference(zval *variable_ptr, zval *value_ptr OPLINE_DC EXECUTE_DATA_DC)
563+
static zend_never_inline ZEND_COLD zval *zend_wrong_assign_to_variable_reference(zval *variable_ptr, zval *value_ptr OPLINE_DC EXECUTE_DATA_DC)
564564
{
565565
zend_error(E_NOTICE, "Only variables should be assigned by reference");
566566
if (UNEXPECTED(EG(exception) != NULL)) {
567-
return 0;
567+
return &EG(uninitialized_zval);
568568
}
569569

570570
/* Use IS_TMP_VAR instead of IS_VAR to avoid ISREF check */
571571
Z_TRY_ADDREF_P(value_ptr);
572-
value_ptr = zend_assign_to_variable(variable_ptr, value_ptr, IS_TMP_VAR, EX_USES_STRICT_TYPES());
573-
574-
return 1;
572+
return zend_assign_to_variable(variable_ptr, value_ptr, IS_TMP_VAR, EX_USES_STRICT_TYPES());
575573
}
576574

577575
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_cannot_pass_by_reference(uint32_t arg_num)
@@ -2910,10 +2908,8 @@ static zend_always_inline void zend_assign_to_property_reference(zval *container
29102908
(opline->extended_value & ZEND_RETURNS_FUNCTION) &&
29112909
UNEXPECTED(!Z_ISREF_P(value_ptr))) {
29122910

2913-
if (UNEXPECTED(!zend_wrong_assign_to_variable_reference(
2914-
variable_ptr, value_ptr OPLINE_CC EXECUTE_DATA_CC))) {
2915-
variable_ptr = &EG(uninitialized_zval);
2916-
}
2911+
variable_ptr = zend_wrong_assign_to_variable_reference(
2912+
variable_ptr, value_ptr OPLINE_CC EXECUTE_DATA_CC);
29172913
} else {
29182914
zend_property_info *prop_info = NULL;
29192915

Zend/zend_vm_def.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2668,9 +2668,8 @@ ZEND_VM_HANDLER(30, ZEND_ASSIGN_REF, VAR|CV, VAR|CV, SRC)
26682668
opline->extended_value == ZEND_RETURNS_FUNCTION &&
26692669
UNEXPECTED(!Z_ISREF_P(value_ptr))) {
26702670

2671-
if (UNEXPECTED(!zend_wrong_assign_to_variable_reference(variable_ptr, value_ptr OPLINE_CC EXECUTE_DATA_CC))) {
2672-
variable_ptr = &EG(uninitialized_zval);
2673-
}
2671+
variable_ptr = zend_wrong_assign_to_variable_reference(
2672+
variable_ptr, value_ptr OPLINE_CC EXECUTE_DATA_CC);
26742673
} else {
26752674
zend_assign_to_variable_reference(variable_ptr, value_ptr);
26762675
}

Zend/zend_vm_execute.h

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27112,9 +27112,8 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ASSIGN_REF_SPEC_VAR_VAR_HANDLE
2711227112
opline->extended_value == ZEND_RETURNS_FUNCTION &&
2711327113
UNEXPECTED(!Z_ISREF_P(value_ptr))) {
2711427114

27115-
if (UNEXPECTED(!zend_wrong_assign_to_variable_reference(variable_ptr, value_ptr OPLINE_CC EXECUTE_DATA_CC))) {
27116-
variable_ptr = &EG(uninitialized_zval);
27117-
}
27115+
variable_ptr = zend_wrong_assign_to_variable_reference(
27116+
variable_ptr, value_ptr OPLINE_CC EXECUTE_DATA_CC);
2711827117
} else {
2711927118
zend_assign_to_variable_reference(variable_ptr, value_ptr);
2712027119
}
@@ -30329,9 +30328,8 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ASSIGN_REF_SPEC_VAR_CV_HANDLER
3032930328
opline->extended_value == ZEND_RETURNS_FUNCTION &&
3033030329
UNEXPECTED(!Z_ISREF_P(value_ptr))) {
3033130330

30332-
if (UNEXPECTED(!zend_wrong_assign_to_variable_reference(variable_ptr, value_ptr OPLINE_CC EXECUTE_DATA_CC))) {
30333-
variable_ptr = &EG(uninitialized_zval);
30334-
}
30331+
variable_ptr = zend_wrong_assign_to_variable_reference(
30332+
variable_ptr, value_ptr OPLINE_CC EXECUTE_DATA_CC);
3033530333
} else {
3033630334
zend_assign_to_variable_reference(variable_ptr, value_ptr);
3033730335
}
@@ -45963,9 +45961,8 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ASSIGN_REF_SPEC_CV_VAR_HANDLER
4596345961
opline->extended_value == ZEND_RETURNS_FUNCTION &&
4596445962
UNEXPECTED(!Z_ISREF_P(value_ptr))) {
4596545963

45966-
if (UNEXPECTED(!zend_wrong_assign_to_variable_reference(variable_ptr, value_ptr OPLINE_CC EXECUTE_DATA_CC))) {
45967-
variable_ptr = &EG(uninitialized_zval);
45968-
}
45964+
variable_ptr = zend_wrong_assign_to_variable_reference(
45965+
variable_ptr, value_ptr OPLINE_CC EXECUTE_DATA_CC);
4596945966
} else {
4597045967
zend_assign_to_variable_reference(variable_ptr, value_ptr);
4597145968
}
@@ -50010,9 +50007,8 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ASSIGN_REF_SPEC_CV_CV_HANDLER(
5001050007
opline->extended_value == ZEND_RETURNS_FUNCTION &&
5001150008
UNEXPECTED(!Z_ISREF_P(value_ptr))) {
5001250009

50013-
if (UNEXPECTED(!zend_wrong_assign_to_variable_reference(variable_ptr, value_ptr OPLINE_CC EXECUTE_DATA_CC))) {
50014-
variable_ptr = &EG(uninitialized_zval);
50015-
}
50010+
variable_ptr = zend_wrong_assign_to_variable_reference(
50011+
variable_ptr, value_ptr OPLINE_CC EXECUTE_DATA_CC);
5001650012
} else {
5001750013
zend_assign_to_variable_reference(variable_ptr, value_ptr);
5001850014
}

0 commit comments

Comments
 (0)