Skip to content

Commit d12d6b5

Browse files
committed
Initial implementation of arbitrary expression interpolation
1 parent 9d5ecf6 commit d12d6b5

9 files changed

+6850
-6087
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Arbitrary expression interpolation
3+
--FILE--
4+
<?php
5+
6+
function a() {return "d";}
7+
$value = 10;
8+
9+
var_dump(
10+
"Result: #{$value * 5}",
11+
"abc#{(function(){return "def";})()}",
12+
"abc#{a()}"
13+
);
14+
?>
15+
--EXPECT--
16+
string(10) "Result: 50"
17+
string(6) "abcdef"
18+
string(6) "abcd"

Zend/zend_ast.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,10 @@ static void zend_ast_export_encaps_list(smart_str *str, char quote, zend_ast_lis
772772
if (ast->kind == ZEND_AST_ZVAL) {
773773
zval *zv = zend_ast_get_zval(ast);
774774

775-
ZEND_ASSERT(Z_TYPE_P(zv) == IS_STRING);
775+
if (Z_TYPE_P(zv) != IS_STRING) {
776+
convert_to_string(zv);
777+
}
778+
776779
zend_ast_export_qstr(str, quote, Z_STR_P(zv));
777780
} else if (ast->kind == ZEND_AST_VAR &&
778781
ast->child[0]->kind == ZEND_AST_ZVAL &&

0 commit comments

Comments
 (0)