diff options
| author | Márcio Almada <marcio3w@gmail.com> | 2016-04-17 04:27:15 -0400 | 
|---|---|---|
| committer | Bob Weinand <bobwei9@hotmail.com> | 2016-04-21 01:22:28 +0200 | 
| commit | 9f3eab44dfc99ac032dbfc84418925ee3adcd175 (patch) | |
| tree | d73c61fdd157be90114f21458c2e7a73c0ca4612 /Zend/zend_ast.c | |
| parent | 85867268fdae2b742ce44bc76b7b57053d5063a8 (diff) | |
| download | php-git-9f3eab44dfc99ac032dbfc84418925ee3adcd175.tar.gz | |
allow null coalescing (??) on constant expressions
Diffstat (limited to 'Zend/zend_ast.c')
| -rw-r--r-- | Zend/zend_ast.c | 39 | 
1 files changed, 38 insertions, 1 deletions
| diff --git a/Zend/zend_ast.c b/Zend/zend_ast.c index cfcd636269..4d3678f0b6 100644 --- a/Zend/zend_ast.c +++ b/Zend/zend_ast.c @@ -337,6 +337,30 @@ ZEND_API int zend_ast_evaluate(zval *result, zend_ast *ast, zend_class_entry *sc  				zval_dtor(&op1);  			}  			break; +		case ZEND_AST_COALESCE: +			if (ast->child[0]->kind == ZEND_AST_DIM) { +				ast->child[0]->attr = ZEND_DIM_IS; +			} + +			if (UNEXPECTED(zend_ast_evaluate(&op1, ast->child[0], scope) != SUCCESS)) { +				ret = FAILURE; +				break; +			} +			if (Z_TYPE(op1) > IS_NULL) { +				*result = op1; +			} else { +				if (ast->child[1]->kind == ZEND_AST_DIM) { +					ast->child[1]->attr = ZEND_DIM_IS; +				} + +				if (UNEXPECTED(zend_ast_evaluate(result, ast->child[1], scope) != SUCCESS)) { +					zval_dtor(&op1); +					ret = FAILURE; +					break; +				} +				zval_dtor(&op1); +			} +			break;  		case ZEND_AST_UNARY_PLUS:  			if (UNEXPECTED(zend_ast_evaluate(&op2, ast->child[0], scope) != SUCCESS)) {  				ret = FAILURE; @@ -385,6 +409,14 @@ ZEND_API int zend_ast_evaluate(zval *result, zend_ast *ast, zend_class_entry *sc  			}  			break;  		case ZEND_AST_DIM: +			if (ast->child[1] == NULL) { +				zend_error_noreturn(E_COMPILE_ERROR, "Cannot use [] for reading"); +			} + +			if (ast->attr == ZEND_DIM_IS && ast->child[0]->kind == ZEND_AST_DIM) { +				ast->child[0]->attr = ZEND_DIM_IS; +			} +  			if (UNEXPECTED(zend_ast_evaluate(&op1, ast->child[0], scope) != SUCCESS)) {  				ret = FAILURE;  			} else if (UNEXPECTED(zend_ast_evaluate(&op2, ast->child[1], scope) != SUCCESS)) { @@ -393,7 +425,12 @@ ZEND_API int zend_ast_evaluate(zval *result, zend_ast *ast, zend_class_entry *sc  			} else {  				zval tmp; -				zend_fetch_dimension_by_zval(&tmp, &op1, &op2); +				if (ast->attr == ZEND_DIM_IS) { +					zend_fetch_dimension_by_zval_is(&tmp, &op1, &op2, IS_CONST); +				} else { +					zend_fetch_dimension_by_zval(&tmp, &op1, &op2); +				} +  				if (UNEXPECTED(Z_ISREF(tmp))) {  					ZVAL_DUP(result, Z_REFVAL(tmp));  				} else { | 
