Skip to content

feat: allow arrow function as a class member #18627

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Zend/zend_language_parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,10 @@ attributed_class_statement:
return_type backup_fn_flags method_body backup_fn_flags
{ $$ = zend_ast_create_decl(ZEND_AST_METHOD, $3 | $1 | $12, $2, $5,
zend_ast_get_str($4), $7, NULL, $11, $9, NULL); CG(extra_fn_flags) = $10; }
| method_modifiers fn returns_ref identifier backup_doc_comment '(' parameter_list ')'
return_type T_DOUBLE_ARROW backup_fn_flags backup_lex_pos expr backup_fn_flags ';'
{ $$ = zend_ast_create_decl(ZEND_AST_METHOD, $3 | $1 | $14, $2, $5,
zend_ast_get_str($4), $7, NULL, zend_ast_create(ZEND_AST_RETURN, $13), $9, NULL); CG(extra_fn_flags) = $11; }
| enum_case { $$ = $1; }
;

Expand Down
25 changes: 25 additions & 0 deletions tests/lang/class_arrow_function_member.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--TEST--
Arrow function as a class member
--FILE--
<?php

class a{
public function test() {
return 111;
}
public fn test2() => 222;
private fn test3() => 333;
static fn test4() => 444;
protected static fn &test5() => 555;
}

$a = new a();

var_dump($a->test());
var_dump($a->test2());
var_dump($a::test4());
?>
--EXPECT--
int(111)
int(222)
int(444)
Loading