Skip to content

Commit 95c0504

Browse files
committed
Deprecate return by ref from void function
Part of https://wiki.php.net/rfc/deprecations_php_8_1.
1 parent 177843c commit 95c0504

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Returning by reference from void function is deprecated
3+
--FILE--
4+
<?php
5+
6+
function &test(): void {
7+
}
8+
9+
$r =& test();
10+
var_dump($r);
11+
12+
?>
13+
--EXPECTF--
14+
Deprecated: Returning by reference from a void function is deprecated in %s on line %d
15+
16+
Notice: Only variable references should be returned by reference in %s on line %d
17+
NULL

Zend/zend_compile.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6532,6 +6532,11 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32_t fall
65326532
}
65336533
arg_infos++;
65346534
op_array->fn_flags |= ZEND_ACC_HAS_RETURN_TYPE;
6535+
6536+
if (ZEND_TYPE_CONTAINS_CODE(arg_infos[-1].type, IS_VOID)
6537+
&& (op_array->fn_flags & ZEND_ACC_RETURN_REFERENCE)) {
6538+
zend_error(E_DEPRECATED, "Returning by reference from a void function is deprecated");
6539+
}
65356540
} else {
65366541
if (list->children == 0) {
65376542
return;

0 commit comments

Comments
 (0)