mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Disallow direct incdec of function return value
Matching PHP 5 behavior. We may want to support this for by-reference returns, but that requires implementing further checks.
This commit is contained in:
parent
f678519a63
commit
c64f5e3332
2 changed files with 19 additions and 1 deletions
14
Zend/tests/increment_function_return_error.phpt
Normal file
14
Zend/tests/increment_function_return_error.phpt
Normal file
|
@ -0,0 +1,14 @@
|
|||
--TEST--
|
||||
It's not possible to increment the return value of a function
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
function test() {
|
||||
return 42;
|
||||
}
|
||||
|
||||
++test();
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Fatal error: Can't use function return value in write context in %s on line %d
|
|
@ -2343,7 +2343,7 @@ static void zend_compile_list_assign(znode *result, zend_ast *ast, znode *expr_n
|
|||
}
|
||||
/* }}} */
|
||||
|
||||
void zend_ensure_writable_variable(const zend_ast *ast) /* {{{ */
|
||||
static void zend_ensure_writable_variable(const zend_ast *ast) /* {{{ */
|
||||
{
|
||||
if (ast->kind == ZEND_AST_CALL) {
|
||||
zend_error_noreturn(E_COMPILE_ERROR, "Can't use function return value in write context");
|
||||
|
@ -5648,6 +5648,8 @@ void zend_compile_post_incdec(znode *result, zend_ast *ast) /* {{{ */
|
|||
zend_ast *var_ast = ast->child[0];
|
||||
ZEND_ASSERT(ast->kind == ZEND_AST_POST_INC || ast->kind == ZEND_AST_POST_DEC);
|
||||
|
||||
zend_ensure_writable_variable(var_ast);
|
||||
|
||||
if (var_ast->kind == ZEND_AST_PROP) {
|
||||
zend_op *opline = zend_compile_prop_common(NULL, var_ast, BP_VAR_RW);
|
||||
opline->opcode = ast->kind == ZEND_AST_POST_INC ? ZEND_POST_INC_OBJ : ZEND_POST_DEC_OBJ;
|
||||
|
@ -5666,6 +5668,8 @@ void zend_compile_pre_incdec(znode *result, zend_ast *ast) /* {{{ */
|
|||
zend_ast *var_ast = ast->child[0];
|
||||
ZEND_ASSERT(ast->kind == ZEND_AST_PRE_INC || ast->kind == ZEND_AST_PRE_DEC);
|
||||
|
||||
zend_ensure_writable_variable(var_ast);
|
||||
|
||||
if (var_ast->kind == ZEND_AST_PROP) {
|
||||
zend_op *opline = zend_compile_prop_common(result, var_ast, BP_VAR_RW);
|
||||
opline->opcode = ast->kind == ZEND_AST_PRE_INC ? ZEND_PRE_INC_OBJ : ZEND_PRE_DEC_OBJ;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue