Skip to content

Commit 6617829

Browse files
committed
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4: Fix return value of wrong fucntion by-ref assign
2 parents 4e66e6a + 96bf925 commit 6617829

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
@@ -569,18 +569,16 @@ static zend_never_inline zval* zend_assign_to_typed_property_reference(zend_prop
569569
return prop;
570570
}
571571

572-
static zend_never_inline ZEND_COLD bool zend_wrong_assign_to_variable_reference(zval *variable_ptr, zval *value_ptr OPLINE_DC EXECUTE_DATA_DC)
572+
static zend_never_inline ZEND_COLD zval *zend_wrong_assign_to_variable_reference(zval *variable_ptr, zval *value_ptr OPLINE_DC EXECUTE_DATA_DC)
573573
{
574574
zend_error(E_NOTICE, "Only variables should be assigned by reference");
575575
if (UNEXPECTED(EG(exception) != NULL)) {
576-
return 0;
576+
return &EG(uninitialized_zval);
577577
}
578578

579579
/* Use IS_TMP_VAR instead of IS_VAR to avoid ISREF check */
580580
Z_TRY_ADDREF_P(value_ptr);
581-
value_ptr = zend_assign_to_variable(variable_ptr, value_ptr, IS_TMP_VAR, EX_USES_STRICT_TYPES());
582-
583-
return 1;
581+
return zend_assign_to_variable(variable_ptr, value_ptr, IS_TMP_VAR, EX_USES_STRICT_TYPES());
584582
}
585583

586584
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_cannot_pass_by_reference(uint32_t arg_num)
@@ -2873,10 +2871,8 @@ static zend_always_inline void zend_assign_to_property_reference(zval *container
28732871
(opline->extended_value & ZEND_RETURNS_FUNCTION) &&
28742872
UNEXPECTED(!Z_ISREF_P(value_ptr))) {
28752873

2876-
if (UNEXPECTED(!zend_wrong_assign_to_variable_reference(
2877-
variable_ptr, value_ptr OPLINE_CC EXECUTE_DATA_CC))) {
2878-
variable_ptr = &EG(uninitialized_zval);
2879-
}
2874+
variable_ptr = zend_wrong_assign_to_variable_reference(
2875+
variable_ptr, value_ptr OPLINE_CC EXECUTE_DATA_CC);
28802876
} else {
28812877
zend_property_info *prop_info = NULL;
28822878

Zend/zend_vm_def.h

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

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

Zend/zend_vm_execute.h

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

26945-
if (UNEXPECTED(!zend_wrong_assign_to_variable_reference(variable_ptr, value_ptr OPLINE_CC EXECUTE_DATA_CC))) {
26946-
variable_ptr = &EG(uninitialized_zval);
26947-
}
26945+
variable_ptr = zend_wrong_assign_to_variable_reference(
26946+
variable_ptr, value_ptr OPLINE_CC EXECUTE_DATA_CC);
2694826947
} else {
2694926948
zend_assign_to_variable_reference(variable_ptr, value_ptr);
2695026949
}
@@ -30171,9 +30170,8 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ASSIGN_REF_SPEC_VAR_CV_HANDLER
3017130170
opline->extended_value == ZEND_RETURNS_FUNCTION &&
3017230171
UNEXPECTED(!Z_ISREF_P(value_ptr))) {
3017330172

30174-
if (UNEXPECTED(!zend_wrong_assign_to_variable_reference(variable_ptr, value_ptr OPLINE_CC EXECUTE_DATA_CC))) {
30175-
variable_ptr = &EG(uninitialized_zval);
30176-
}
30173+
variable_ptr = zend_wrong_assign_to_variable_reference(
30174+
variable_ptr, value_ptr OPLINE_CC EXECUTE_DATA_CC);
3017730175
} else {
3017830176
zend_assign_to_variable_reference(variable_ptr, value_ptr);
3017930177
}
@@ -45807,9 +45805,8 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ASSIGN_REF_SPEC_CV_VAR_HANDLER
4580745805
opline->extended_value == ZEND_RETURNS_FUNCTION &&
4580845806
UNEXPECTED(!Z_ISREF_P(value_ptr))) {
4580945807

45810-
if (UNEXPECTED(!zend_wrong_assign_to_variable_reference(variable_ptr, value_ptr OPLINE_CC EXECUTE_DATA_CC))) {
45811-
variable_ptr = &EG(uninitialized_zval);
45812-
}
45808+
variable_ptr = zend_wrong_assign_to_variable_reference(
45809+
variable_ptr, value_ptr OPLINE_CC EXECUTE_DATA_CC);
4581345810
} else {
4581445811
zend_assign_to_variable_reference(variable_ptr, value_ptr);
4581545812
}
@@ -49870,9 +49867,8 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ASSIGN_REF_SPEC_CV_CV_HANDLER(
4987049867
opline->extended_value == ZEND_RETURNS_FUNCTION &&
4987149868
UNEXPECTED(!Z_ISREF_P(value_ptr))) {
4987249869

49873-
if (UNEXPECTED(!zend_wrong_assign_to_variable_reference(variable_ptr, value_ptr OPLINE_CC EXECUTE_DATA_CC))) {
49874-
variable_ptr = &EG(uninitialized_zval);
49875-
}
49870+
variable_ptr = zend_wrong_assign_to_variable_reference(
49871+
variable_ptr, value_ptr OPLINE_CC EXECUTE_DATA_CC);
4987649872
} else {
4987749873
zend_assign_to_variable_reference(variable_ptr, value_ptr);
4987849874
}

0 commit comments

Comments
 (0)