Skip to content

Commit 8142547

Browse files
committed
Unsuccessful attempt to fix the namespace issue.
1 parent d5a5dc8 commit 8142547

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
Functions in namespaces can be piped
3+
--FILE--
4+
<?php
5+
6+
namespace Beep {
7+
function test(int $x) {
8+
print $x;
9+
}
10+
}
11+
12+
namespace Bar {
13+
use function \Beep\test;
14+
15+
5 |> test(...);
16+
}
17+
18+
?>
19+
--EXPECT--
20+
5

Zend/zend_compile.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6417,23 +6417,26 @@ static void zend_compile_pipe(znode *result, zend_ast *ast)
64176417
zend_ast *operand_ast = ast->child[0];
64186418
zend_ast *callable_ast = ast->child[1];
64196419

6420+
// Execute everything on the left side first, down to a value.
64206421
znode operand_result;
64216422
zend_compile_expr(&operand_result, operand_ast);
6423+
6424+
// Wrap the operand in a ZEND_QM_ASSIGN to prevent references
6425+
// from working in all cases. (Otherwise they'd fail only in some.)
64226426
znode wrapped_operand_result;
64236427
zend_emit_op_tmp(&wrapped_operand_result, ZEND_QM_ASSIGN, &operand_result, NULL);
64246428

6425-
/* Turn $foo |> bar(...) into bar($foo). */
6429+
// Turn $foo |> bar(...) into bar($foo).
64266430
if (callable_ast->kind == ZEND_AST_CALL
64276431
&& callable_ast->child[1]->kind == ZEND_AST_CALLABLE_CONVERT) {
64286432
callable_ast = callable_ast->child[0];
6433+
} else {
6434+
znode callable_result;
6435+
callable_ast = zend_ast_create_znode(&callable_result);
6436+
zend_compile_expr(&callable_result, callable_ast);
64296437
}
64306438

6431-
znode callable_result;
6432-
zend_compile_expr(&callable_result, callable_ast);
6433-
6434-
zend_ast *fcall_ast = zend_ast_create(ZEND_AST_CALL,
6435-
zend_ast_create_znode(&callable_result),
6436-
zend_ast_create_list(1, ZEND_AST_ARG_LIST, zend_ast_create_znode(&wrapped_operand_result)));
6439+
zend_ast *fcall_ast = zend_ast_create_list(1, ZEND_AST_ARG_LIST, zend_ast_create_znode(&wrapped_operand_result));
64376440

64386441
zend_compile_expr(result, fcall_ast);
64396442
}

0 commit comments

Comments
 (0)