Skip to content

Commit

Permalink
Deprecate return by ref from void function
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Jul 8, 2021
1 parent bf94010 commit f0b190c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,9 @@ PHP 8.1 UPGRADE NOTES
e.g. a truncation from 1.9 to 1, is deprecated. This affects array keys,
int parameter and return types, and operators working on integers.
RFC: https://wiki.php.net/rfc/implicit-float-int-deprecate
. returning a non-array from __sleep will raise a warning
. Returning a non-array from __sleep will raise a warning
. Returning by reference from a void function is deprecated.
RFC: https://wiki.php.net/rfc/deprecations_php_8_1

- Date:
. The date_sunrise() and date_sunset() functions have been deprecated in
Expand Down
17 changes: 17 additions & 0 deletions Zend/tests/return_by_ref_from_void_function.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
Returning by reference from void function is deprecated
--FILE--
<?php

function &test(): void {
}

$r =& test();
var_dump($r);

?>
--EXPECTF--
Deprecated: Returning by reference from a void function is deprecated in %s on line %d

Notice: Only variable references should be returned by reference in %s on line %d
NULL
5 changes: 5 additions & 0 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -6532,6 +6532,11 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32_t fall
}
arg_infos++;
op_array->fn_flags |= ZEND_ACC_HAS_RETURN_TYPE;

if (ZEND_TYPE_CONTAINS_CODE(arg_infos[-1].type, IS_VOID)
&& (op_array->fn_flags & ZEND_ACC_RETURN_REFERENCE)) {
zend_error(E_DEPRECATED, "Returning by reference from a void function is deprecated");
}
} else {
if (list->children == 0) {
return;
Expand Down

0 comments on commit f0b190c

Please sign in to comment.