Skip to content

Commit a8f0185

Browse files
committed
Use 'fn' for expression functions
1 parent 5bec932 commit a8f0185

File tree

6 files changed

+13
-10
lines changed

6 files changed

+13
-10
lines changed

Zend/tests/short_functions/short-func-match.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Short functions with match statements.
33
--FILE--
44
<?php
55

6-
function pick_one(int $a) => match($a) {
6+
fn pick_one(int $a) => match($a) {
77
1 => 'One',
88
2 => 'Two',
99
3 => 'Three',

Zend/tests/short_functions/short-func-no-statement.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Non-expression statements parse error in short functions.
33
--FILE--
44
<?php
55

6-
function test(array $a) => foreach ($a as $v) print $v;
6+
fn test(array $a) => foreach ($a as $v) print $v;
77

88
test([1, 2, 3]);
99

Zend/tests/short_functions/short-func.phpt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ Basic short functions return values.
33
--FILE--
44
<?php
55

6-
function test(int $a) => $a + 1;
6+
fn test(int $a) => $a + 1;
77

8-
function test2(int $b): int
9-
=> $b + 1;
8+
fn test2(int $b): int => $b + 1;
109

1110
print test(5) . PHP_EOL;
1211
print test2(5) . PHP_EOL;

Zend/tests/short_functions/short-method-no-statement.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class Test {
77

88
public function __construct(private int $b) {}
99

10-
public function out(array $a) => foreach ($a as $v) print $v;
10+
public fn out(array $a) => foreach ($a as $v) print $v;
1111
}
1212

1313
$t = new Test(1);

Zend/tests/short_functions/short-method.phpt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ class Test {
77

88
public function __construct(private int $b) {}
99

10-
public function addUp(int $a) => $a + $this->b;
10+
public fn addUp(int $a) => $a + $this->b;
1111

12-
public function addUp2(int $a): int
13-
=> $a + $this->b;
12+
public fn addUp2(int $a): int => $a + $this->b;
1413
}
1514

1615
$t = new Test(1);

Zend/zend_language_parser.y

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ function_declaration_statement:
548548
backup_fn_flags '{' inner_statement_list '}' backup_fn_flags
549549
{ $$ = zend_ast_create_decl(ZEND_AST_FUNC_DECL, $2 | $13, $1, $4,
550550
zend_ast_get_str($3), $6, NULL, $11, $8, NULL); CG(extra_fn_flags) = $9; }
551-
| function returns_ref T_STRING backup_doc_comment '(' parameter_list ')' return_type
551+
| fn returns_ref T_STRING backup_doc_comment '(' parameter_list ')' return_type
552552
backup_fn_flags T_DOUBLE_ARROW expr ';' backup_fn_flags
553553
{ $$ = zend_ast_create_decl(ZEND_AST_FUNC_DECL, $2, $1, $4,
554554
zend_ast_get_str($3), $6, NULL, zend_ast_create(ZEND_AST_RETURN, $11), $8, NULL); CG(extra_fn_flags) = $9; }
@@ -863,6 +863,11 @@ attributed_class_statement:
863863
return_type backup_fn_flags method_body backup_fn_flags
864864
{ $$ = zend_ast_create_decl(ZEND_AST_METHOD, $3 | $1 | $12, $2, $5,
865865
zend_ast_get_str($4), $7, NULL, $11, $9, NULL); CG(extra_fn_flags) = $10; }
866+
| method_modifiers fn returns_ref identifier backup_doc_comment '(' parameter_list ')'
867+
return_type backup_fn_flags T_DOUBLE_ARROW expr ';' backup_fn_flags
868+
{ $$ = zend_ast_create_decl(ZEND_AST_METHOD, $3 | $1 | $14, $2, $5,
869+
zend_ast_get_str($4), $7, NULL, zend_ast_create(ZEND_AST_RETURN, $12), $9, NULL);
870+
CG(extra_fn_flags) = $10; }
866871
;
867872

868873
class_statement:

0 commit comments

Comments
 (0)