From 0098f2f2ccd0690397c31f61337dcc1fbfacd1df Mon Sep 17 00:00:00 2001 From: Valentin Udaltsov Date: Tue, 26 Dec 2023 15:08:00 +0300 Subject: [PATCH 01/11] Split new_expr to new_(with|without)_parentheses, new_with_parentheses is now a callable_variable --- Zend/zend_language_parser.y | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Zend/zend_language_parser.y b/Zend/zend_language_parser.y index 6e882f922f374..57e7ddbce1537 100644 --- a/Zend/zend_language_parser.y +++ b/Zend/zend_language_parser.y @@ -255,7 +255,7 @@ static YYSIZE_T zend_yytnamerr(char*, const char*); %type extends_from parameter optional_type_without_static argument global_var %type static_var class_statement trait_adaptation trait_precedence trait_alias %type absolute_trait_method_reference trait_method_reference property echo_expr -%type new_expr anonymous_class class_name class_name_reference simple_variable +%type new_with_parentheses new_without_parentheses anonymous_class class_name class_name_reference simple_variable %type internal_functions_in_yacc %type exit_expr scalar backticks_expr lexical_var function_call member_name property_name %type variable_class_name dereferenceable_scalar constant class_constant @@ -1123,8 +1123,8 @@ anonymous_class: } ; -new_expr: - T_NEW class_name_reference ctor_arguments +new_with_parentheses: + T_NEW class_name_reference argument_list { $$ = zend_ast_create(ZEND_AST_NEW, $2, $3); } | T_NEW anonymous_class { $$ = $2; } @@ -1132,6 +1132,11 @@ new_expr: { zend_ast_with_attributes($3->child[0], $2); $$ = $3; } ; +new_without_parentheses: + T_NEW class_name_reference + { $$ = zend_ast_create(ZEND_AST_NEW, $2, zend_ast_create_list(0, ZEND_AST_ARG_LIST)); } +; + expr: variable { $$ = $1; } @@ -1225,7 +1230,7 @@ expr: $$ = $2; if ($$->kind == ZEND_AST_CONDITIONAL) $$->attr = ZEND_PARENTHESIZED_CONDITIONAL; } - | new_expr { $$ = $1; } + | new_without_parentheses { $$ = $1; } | expr '?' expr ':' expr { $$ = zend_ast_create(ZEND_AST_CONDITIONAL, $1, $3, $5); } | expr '?' ':' expr @@ -1443,6 +1448,7 @@ callable_variable: | array_object_dereferenceable T_NULLSAFE_OBJECT_OPERATOR property_name argument_list { $$ = zend_ast_create(ZEND_AST_NULLSAFE_METHOD_CALL, $1, $3, $4); } | function_call { $$ = $1; } + | new_with_parentheses { $$ = $1; } ; variable: From 4f7e6bafb45c8f8a180d5ab7c8ef42383ca8a742 Mon Sep 17 00:00:00 2001 From: Valentin Udaltsov Date: Tue, 26 Dec 2023 15:09:45 +0300 Subject: [PATCH 02/11] Added tests --- .../new_class_constant.phpt | 15 ++++++++++++++ .../new_class_invoke.phpt | 18 +++++++++++++++++ .../new_class_method.phpt | 18 +++++++++++++++++ .../new_class_property.phpt | 15 ++++++++++++++ .../new_class_static_method.phpt | 18 +++++++++++++++++ .../new_class_static_property.phpt | 15 ++++++++++++++ .../new_expr_constant.phpt | 15 ++++++++++++++ .../new_expr_invoke.phpt | 18 +++++++++++++++++ .../new_expr_method.phpt | 18 +++++++++++++++++ .../new_expr_property.phpt | 15 ++++++++++++++ .../new_expr_static_method.phpt | 18 +++++++++++++++++ .../new_expr_static_property.phpt | 15 ++++++++++++++ .../new_var_constant.phpt | 17 ++++++++++++++++ .../new_var_invoke.phpt | 20 +++++++++++++++++++ .../new_var_method.phpt | 20 +++++++++++++++++++ .../new_var_property.phpt | 17 ++++++++++++++++ .../new_var_static_method.phpt | 20 +++++++++++++++++++ .../new_var_static_property.phpt | 17 ++++++++++++++++ 18 files changed, 309 insertions(+) create mode 100644 Zend/tests/new_obj_access_without_parentheses/new_class_constant.phpt create mode 100644 Zend/tests/new_obj_access_without_parentheses/new_class_invoke.phpt create mode 100644 Zend/tests/new_obj_access_without_parentheses/new_class_method.phpt create mode 100644 Zend/tests/new_obj_access_without_parentheses/new_class_property.phpt create mode 100644 Zend/tests/new_obj_access_without_parentheses/new_class_static_method.phpt create mode 100644 Zend/tests/new_obj_access_without_parentheses/new_class_static_property.phpt create mode 100644 Zend/tests/new_obj_access_without_parentheses/new_expr_constant.phpt create mode 100644 Zend/tests/new_obj_access_without_parentheses/new_expr_invoke.phpt create mode 100644 Zend/tests/new_obj_access_without_parentheses/new_expr_method.phpt create mode 100644 Zend/tests/new_obj_access_without_parentheses/new_expr_property.phpt create mode 100644 Zend/tests/new_obj_access_without_parentheses/new_expr_static_method.phpt create mode 100644 Zend/tests/new_obj_access_without_parentheses/new_expr_static_property.phpt create mode 100644 Zend/tests/new_obj_access_without_parentheses/new_var_constant.phpt create mode 100644 Zend/tests/new_obj_access_without_parentheses/new_var_invoke.phpt create mode 100644 Zend/tests/new_obj_access_without_parentheses/new_var_method.phpt create mode 100644 Zend/tests/new_obj_access_without_parentheses/new_var_property.phpt create mode 100644 Zend/tests/new_obj_access_without_parentheses/new_var_static_method.phpt create mode 100644 Zend/tests/new_obj_access_without_parentheses/new_var_static_property.phpt diff --git a/Zend/tests/new_obj_access_without_parentheses/new_class_constant.phpt b/Zend/tests/new_obj_access_without_parentheses/new_class_constant.phpt new file mode 100644 index 0000000000000..082a9d5211824 --- /dev/null +++ b/Zend/tests/new_obj_access_without_parentheses/new_class_constant.phpt @@ -0,0 +1,15 @@ +--TEST-- +Immediate constant access on new object with ctor parentheses +--FILE-- + +--EXPECT-- +constant diff --git a/Zend/tests/new_obj_access_without_parentheses/new_class_invoke.phpt b/Zend/tests/new_obj_access_without_parentheses/new_class_invoke.phpt new file mode 100644 index 0000000000000..8bf8cd88c42e5 --- /dev/null +++ b/Zend/tests/new_obj_access_without_parentheses/new_class_invoke.phpt @@ -0,0 +1,18 @@ +--TEST-- +Immediate invocation of new object with ctor parentheses +--FILE-- + +--EXPECT-- +invoked diff --git a/Zend/tests/new_obj_access_without_parentheses/new_class_method.phpt b/Zend/tests/new_obj_access_without_parentheses/new_class_method.phpt new file mode 100644 index 0000000000000..afd72fea297a2 --- /dev/null +++ b/Zend/tests/new_obj_access_without_parentheses/new_class_method.phpt @@ -0,0 +1,18 @@ +--TEST-- +Immediate method call on new object with ctor parentheses +--FILE-- +test(); + +?> +--EXPECT-- +called diff --git a/Zend/tests/new_obj_access_without_parentheses/new_class_property.phpt b/Zend/tests/new_obj_access_without_parentheses/new_class_property.phpt new file mode 100644 index 0000000000000..ce456aaea612b --- /dev/null +++ b/Zend/tests/new_obj_access_without_parentheses/new_class_property.phpt @@ -0,0 +1,15 @@ +--TEST-- +Immediate property access on new object with ctor parentheses +--FILE-- +prop; + +?> +--EXPECT-- +property diff --git a/Zend/tests/new_obj_access_without_parentheses/new_class_static_method.phpt b/Zend/tests/new_obj_access_without_parentheses/new_class_static_method.phpt new file mode 100644 index 0000000000000..25250dc43f6d0 --- /dev/null +++ b/Zend/tests/new_obj_access_without_parentheses/new_class_static_method.phpt @@ -0,0 +1,18 @@ +--TEST-- +Immediate static method call on new object with ctor parentheses +--FILE-- + +--EXPECT-- +called diff --git a/Zend/tests/new_obj_access_without_parentheses/new_class_static_property.phpt b/Zend/tests/new_obj_access_without_parentheses/new_class_static_property.phpt new file mode 100644 index 0000000000000..ac96bd43e0c7b --- /dev/null +++ b/Zend/tests/new_obj_access_without_parentheses/new_class_static_property.phpt @@ -0,0 +1,15 @@ +--TEST-- +Immediate static property access on new object with ctor parentheses +--FILE-- + +--EXPECT-- +property diff --git a/Zend/tests/new_obj_access_without_parentheses/new_expr_constant.phpt b/Zend/tests/new_obj_access_without_parentheses/new_expr_constant.phpt new file mode 100644 index 0000000000000..90ceaf60b6db9 --- /dev/null +++ b/Zend/tests/new_obj_access_without_parentheses/new_expr_constant.phpt @@ -0,0 +1,15 @@ +--TEST-- +Immediate constant access on new object with ctor parentheses created from expr +--FILE-- + +--EXPECT-- +constant diff --git a/Zend/tests/new_obj_access_without_parentheses/new_expr_invoke.phpt b/Zend/tests/new_obj_access_without_parentheses/new_expr_invoke.phpt new file mode 100644 index 0000000000000..39bc737ad48c0 --- /dev/null +++ b/Zend/tests/new_obj_access_without_parentheses/new_expr_invoke.phpt @@ -0,0 +1,18 @@ +--TEST-- +Immediate invocation of new object with ctor parentheses created from expr +--FILE-- + +--EXPECT-- +invoked diff --git a/Zend/tests/new_obj_access_without_parentheses/new_expr_method.phpt b/Zend/tests/new_obj_access_without_parentheses/new_expr_method.phpt new file mode 100644 index 0000000000000..09e8bea4c77d0 --- /dev/null +++ b/Zend/tests/new_obj_access_without_parentheses/new_expr_method.phpt @@ -0,0 +1,18 @@ +--TEST-- +Immediate method call on new object with ctor parentheses created from expr +--FILE-- +test(); + +?> +--EXPECT-- +called diff --git a/Zend/tests/new_obj_access_without_parentheses/new_expr_property.phpt b/Zend/tests/new_obj_access_without_parentheses/new_expr_property.phpt new file mode 100644 index 0000000000000..b3c952aae2f6c --- /dev/null +++ b/Zend/tests/new_obj_access_without_parentheses/new_expr_property.phpt @@ -0,0 +1,15 @@ +--TEST-- +Immediate property access on new object with ctor parentheses created from expr +--FILE-- +prop; + +?> +--EXPECT-- +property diff --git a/Zend/tests/new_obj_access_without_parentheses/new_expr_static_method.phpt b/Zend/tests/new_obj_access_without_parentheses/new_expr_static_method.phpt new file mode 100644 index 0000000000000..3a30ab4f77aac --- /dev/null +++ b/Zend/tests/new_obj_access_without_parentheses/new_expr_static_method.phpt @@ -0,0 +1,18 @@ +--TEST-- +Immediate static method call on new object with ctor parentheses created from expr +--FILE-- + +--EXPECT-- +called diff --git a/Zend/tests/new_obj_access_without_parentheses/new_expr_static_property.phpt b/Zend/tests/new_obj_access_without_parentheses/new_expr_static_property.phpt new file mode 100644 index 0000000000000..6aad5fdbd701d --- /dev/null +++ b/Zend/tests/new_obj_access_without_parentheses/new_expr_static_property.phpt @@ -0,0 +1,15 @@ +--TEST-- +Immediate static property access on new object with ctor parentheses created from expr +--FILE-- + +--EXPECT-- +property diff --git a/Zend/tests/new_obj_access_without_parentheses/new_var_constant.phpt b/Zend/tests/new_obj_access_without_parentheses/new_var_constant.phpt new file mode 100644 index 0000000000000..09dbe4b4b29bf --- /dev/null +++ b/Zend/tests/new_obj_access_without_parentheses/new_var_constant.phpt @@ -0,0 +1,17 @@ +--TEST-- +Immediate constant access on new object with ctor parentheses created from var +--FILE-- + +--EXPECT-- +constant diff --git a/Zend/tests/new_obj_access_without_parentheses/new_var_invoke.phpt b/Zend/tests/new_obj_access_without_parentheses/new_var_invoke.phpt new file mode 100644 index 0000000000000..52e88a57113da --- /dev/null +++ b/Zend/tests/new_obj_access_without_parentheses/new_var_invoke.phpt @@ -0,0 +1,20 @@ +--TEST-- +Immediate invocation of new object with ctor parentheses created from var +--FILE-- + +--EXPECT-- +invoked diff --git a/Zend/tests/new_obj_access_without_parentheses/new_var_method.phpt b/Zend/tests/new_obj_access_without_parentheses/new_var_method.phpt new file mode 100644 index 0000000000000..c7f67cbceb8fa --- /dev/null +++ b/Zend/tests/new_obj_access_without_parentheses/new_var_method.phpt @@ -0,0 +1,20 @@ +--TEST-- +Immediate method call on new object with ctor parentheses created from var +--FILE-- +test(); + +?> +--EXPECT-- +called diff --git a/Zend/tests/new_obj_access_without_parentheses/new_var_property.phpt b/Zend/tests/new_obj_access_without_parentheses/new_var_property.phpt new file mode 100644 index 0000000000000..e2f9b37342a00 --- /dev/null +++ b/Zend/tests/new_obj_access_without_parentheses/new_var_property.phpt @@ -0,0 +1,17 @@ +--TEST-- +Immediate property access on new object with ctor parentheses created from var +--FILE-- +prop; + +?> +--EXPECT-- +property diff --git a/Zend/tests/new_obj_access_without_parentheses/new_var_static_method.phpt b/Zend/tests/new_obj_access_without_parentheses/new_var_static_method.phpt new file mode 100644 index 0000000000000..89511f0277ab1 --- /dev/null +++ b/Zend/tests/new_obj_access_without_parentheses/new_var_static_method.phpt @@ -0,0 +1,20 @@ +--TEST-- +Immediate static method call on new object with ctor parentheses created from var +--FILE-- + +--EXPECT-- +called diff --git a/Zend/tests/new_obj_access_without_parentheses/new_var_static_property.phpt b/Zend/tests/new_obj_access_without_parentheses/new_var_static_property.phpt new file mode 100644 index 0000000000000..22d2c893ddb27 --- /dev/null +++ b/Zend/tests/new_obj_access_without_parentheses/new_var_static_property.phpt @@ -0,0 +1,17 @@ +--TEST-- +Immediate static property access on new object with ctor parentheses created from var +--FILE-- + +--EXPECT-- +property From a6a56c6574d64677068a1e4c265ab73442b467ca Mon Sep 17 00:00:00 2001 From: Valentin Udaltsov Date: Tue, 26 Dec 2023 21:25:27 +0300 Subject: [PATCH 03/11] Added anonymous class tests --- .../new_anonymous_constant.phpt | 12 ++++++++++++ .../new_anonymous_invoke.phpt | 15 +++++++++++++++ .../new_anonymous_method.phpt | 15 +++++++++++++++ .../new_anonymous_property.phpt | 12 ++++++++++++ .../new_anonymous_static_method.phpt | 15 +++++++++++++++ .../new_anonymous_static_property.phpt | 12 ++++++++++++ 6 files changed, 81 insertions(+) create mode 100644 Zend/tests/new_obj_access_without_parentheses/new_anonymous_constant.phpt create mode 100644 Zend/tests/new_obj_access_without_parentheses/new_anonymous_invoke.phpt create mode 100644 Zend/tests/new_obj_access_without_parentheses/new_anonymous_method.phpt create mode 100644 Zend/tests/new_obj_access_without_parentheses/new_anonymous_property.phpt create mode 100644 Zend/tests/new_obj_access_without_parentheses/new_anonymous_static_method.phpt create mode 100644 Zend/tests/new_obj_access_without_parentheses/new_anonymous_static_property.phpt diff --git a/Zend/tests/new_obj_access_without_parentheses/new_anonymous_constant.phpt b/Zend/tests/new_obj_access_without_parentheses/new_anonymous_constant.phpt new file mode 100644 index 0000000000000..ee87e0b550f2a --- /dev/null +++ b/Zend/tests/new_obj_access_without_parentheses/new_anonymous_constant.phpt @@ -0,0 +1,12 @@ +--TEST-- +Immediate constant access on new anonymous class object +--FILE-- + +--EXPECT-- +constant diff --git a/Zend/tests/new_obj_access_without_parentheses/new_anonymous_invoke.phpt b/Zend/tests/new_obj_access_without_parentheses/new_anonymous_invoke.phpt new file mode 100644 index 0000000000000..963c39ae31488 --- /dev/null +++ b/Zend/tests/new_obj_access_without_parentheses/new_anonymous_invoke.phpt @@ -0,0 +1,15 @@ +--TEST-- +Immediate invocation of new anonymous class object +--FILE-- + +--EXPECT-- +invoked diff --git a/Zend/tests/new_obj_access_without_parentheses/new_anonymous_method.phpt b/Zend/tests/new_obj_access_without_parentheses/new_anonymous_method.phpt new file mode 100644 index 0000000000000..133436600139d --- /dev/null +++ b/Zend/tests/new_obj_access_without_parentheses/new_anonymous_method.phpt @@ -0,0 +1,15 @@ +--TEST-- +Immediate method call on new anonymous class object +--FILE-- +test(); + +?> +--EXPECT-- +called diff --git a/Zend/tests/new_obj_access_without_parentheses/new_anonymous_property.phpt b/Zend/tests/new_obj_access_without_parentheses/new_anonymous_property.phpt new file mode 100644 index 0000000000000..33c652c943308 --- /dev/null +++ b/Zend/tests/new_obj_access_without_parentheses/new_anonymous_property.phpt @@ -0,0 +1,12 @@ +--TEST-- +Immediate property access on new anonymous class object +--FILE-- +property; + +?> +--EXPECT-- +property diff --git a/Zend/tests/new_obj_access_without_parentheses/new_anonymous_static_method.phpt b/Zend/tests/new_obj_access_without_parentheses/new_anonymous_static_method.phpt new file mode 100644 index 0000000000000..e6dea32dc85a0 --- /dev/null +++ b/Zend/tests/new_obj_access_without_parentheses/new_anonymous_static_method.phpt @@ -0,0 +1,15 @@ +--TEST-- +Immediate static method call on new anonymous class object +--FILE-- +test(); + +?> +--EXPECT-- +called diff --git a/Zend/tests/new_obj_access_without_parentheses/new_anonymous_static_property.phpt b/Zend/tests/new_obj_access_without_parentheses/new_anonymous_static_property.phpt new file mode 100644 index 0000000000000..0027f1b629363 --- /dev/null +++ b/Zend/tests/new_obj_access_without_parentheses/new_anonymous_static_property.phpt @@ -0,0 +1,12 @@ +--TEST-- +Immediate static property access on new anonymous class object +--FILE-- + +--EXPECT-- +staticProperty From 6dbfc6284a3e188b3e0e47030e738010ddea79d1 Mon Sep 17 00:00:00 2001 From: Valentin Udaltsov Date: Tue, 26 Dec 2023 22:47:26 +0300 Subject: [PATCH 04/11] Fixed new_anonymous_static_method.phpt --- .../new_anonymous_static_method.phpt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Zend/tests/new_obj_access_without_parentheses/new_anonymous_static_method.phpt b/Zend/tests/new_obj_access_without_parentheses/new_anonymous_static_method.phpt index e6dea32dc85a0..1a37317023811 100644 --- a/Zend/tests/new_obj_access_without_parentheses/new_anonymous_static_method.phpt +++ b/Zend/tests/new_obj_access_without_parentheses/new_anonymous_static_method.phpt @@ -4,11 +4,11 @@ Immediate static method call on new anonymous class object test(); +}::test(); ?> --EXPECT-- From aa5cfaeed9354bdfa9b0de5f719a0797083b291d Mon Sep 17 00:00:00 2001 From: Valentin Udaltsov Date: Thu, 28 Dec 2023 14:51:25 +0300 Subject: [PATCH 05/11] Renamed new_(with|without)_parentheses to new_(dereferenceable|non_dereferenceable) --- Zend/zend_language_parser.y | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Zend/zend_language_parser.y b/Zend/zend_language_parser.y index 57e7ddbce1537..097ce789dc3b7 100644 --- a/Zend/zend_language_parser.y +++ b/Zend/zend_language_parser.y @@ -255,7 +255,7 @@ static YYSIZE_T zend_yytnamerr(char*, const char*); %type extends_from parameter optional_type_without_static argument global_var %type static_var class_statement trait_adaptation trait_precedence trait_alias %type absolute_trait_method_reference trait_method_reference property echo_expr -%type new_with_parentheses new_without_parentheses anonymous_class class_name class_name_reference simple_variable +%type new_dereferenceable new_non_dereferenceable anonymous_class class_name class_name_reference simple_variable %type internal_functions_in_yacc %type exit_expr scalar backticks_expr lexical_var function_call member_name property_name %type variable_class_name dereferenceable_scalar constant class_constant @@ -1123,7 +1123,7 @@ anonymous_class: } ; -new_with_parentheses: +new_dereferenceable: T_NEW class_name_reference argument_list { $$ = zend_ast_create(ZEND_AST_NEW, $2, $3); } | T_NEW anonymous_class @@ -1132,7 +1132,7 @@ new_with_parentheses: { zend_ast_with_attributes($3->child[0], $2); $$ = $3; } ; -new_without_parentheses: +new_non_dereferenceable: T_NEW class_name_reference { $$ = zend_ast_create(ZEND_AST_NEW, $2, zend_ast_create_list(0, ZEND_AST_ARG_LIST)); } ; @@ -1230,7 +1230,7 @@ expr: $$ = $2; if ($$->kind == ZEND_AST_CONDITIONAL) $$->attr = ZEND_PARENTHESIZED_CONDITIONAL; } - | new_without_parentheses { $$ = $1; } + | new_non_dereferenceable { $$ = $1; } | expr '?' expr ':' expr { $$ = zend_ast_create(ZEND_AST_CONDITIONAL, $1, $3, $5); } | expr '?' ':' expr @@ -1448,7 +1448,7 @@ callable_variable: | array_object_dereferenceable T_NULLSAFE_OBJECT_OPERATOR property_name argument_list { $$ = zend_ast_create(ZEND_AST_NULLSAFE_METHOD_CALL, $1, $3, $4); } | function_call { $$ = $1; } - | new_with_parentheses { $$ = $1; } + | new_dereferenceable { $$ = $1; } ; variable: From d33b2992801a86b252dc903e4e4477d43f2e2a82 Mon Sep 17 00:00:00 2001 From: Valentin Udaltsov Date: Thu, 28 Dec 2023 15:01:19 +0300 Subject: [PATCH 06/11] Added no constructor parentheses tests --- ...ew_class_no_ctor_parentheses_constant.phpt | 15 ++++++++++++++ .../new_class_no_ctor_parentheses_method.phpt | 18 +++++++++++++++++ ...ew_class_no_ctor_parentheses_property.phpt | 15 ++++++++++++++ ...ass_no_ctor_parentheses_static_method.phpt | 18 +++++++++++++++++ ...s_no_ctor_parentheses_static_property.phpt | 20 +++++++++++++++++++ 5 files changed, 86 insertions(+) create mode 100644 Zend/tests/new_obj_access_without_parentheses/new_class_no_ctor_parentheses_constant.phpt create mode 100644 Zend/tests/new_obj_access_without_parentheses/new_class_no_ctor_parentheses_method.phpt create mode 100644 Zend/tests/new_obj_access_without_parentheses/new_class_no_ctor_parentheses_property.phpt create mode 100644 Zend/tests/new_obj_access_without_parentheses/new_class_no_ctor_parentheses_static_method.phpt create mode 100644 Zend/tests/new_obj_access_without_parentheses/new_class_no_ctor_parentheses_static_property.phpt diff --git a/Zend/tests/new_obj_access_without_parentheses/new_class_no_ctor_parentheses_constant.phpt b/Zend/tests/new_obj_access_without_parentheses/new_class_no_ctor_parentheses_constant.phpt new file mode 100644 index 0000000000000..a1085b81558c4 --- /dev/null +++ b/Zend/tests/new_obj_access_without_parentheses/new_class_no_ctor_parentheses_constant.phpt @@ -0,0 +1,15 @@ +--TEST-- +Immediate constant access on new object with ctor parentheses +--FILE-- + +--EXPECTF-- +Parse error: syntax error, unexpected identifier "C", expecting variable or "$" in %s on line %d diff --git a/Zend/tests/new_obj_access_without_parentheses/new_class_no_ctor_parentheses_method.phpt b/Zend/tests/new_obj_access_without_parentheses/new_class_no_ctor_parentheses_method.phpt new file mode 100644 index 0000000000000..64a0fa5ba4d39 --- /dev/null +++ b/Zend/tests/new_obj_access_without_parentheses/new_class_no_ctor_parentheses_method.phpt @@ -0,0 +1,18 @@ +--TEST-- +Immediate method call on new object with ctor parentheses +--FILE-- +test(); + +?> +--EXPECTF-- +Parse error: syntax error, unexpected token "->" in %s on line %d diff --git a/Zend/tests/new_obj_access_without_parentheses/new_class_no_ctor_parentheses_property.phpt b/Zend/tests/new_obj_access_without_parentheses/new_class_no_ctor_parentheses_property.phpt new file mode 100644 index 0000000000000..5613dcb192776 --- /dev/null +++ b/Zend/tests/new_obj_access_without_parentheses/new_class_no_ctor_parentheses_property.phpt @@ -0,0 +1,15 @@ +--TEST-- +Immediate property access on new object with ctor parentheses +--FILE-- +prop; + +?> +--EXPECTF-- +Parse error: syntax error, unexpected token "->", expecting "," or ";" in %s on line %d diff --git a/Zend/tests/new_obj_access_without_parentheses/new_class_no_ctor_parentheses_static_method.phpt b/Zend/tests/new_obj_access_without_parentheses/new_class_no_ctor_parentheses_static_method.phpt new file mode 100644 index 0000000000000..2adc3fb460ca6 --- /dev/null +++ b/Zend/tests/new_obj_access_without_parentheses/new_class_no_ctor_parentheses_static_method.phpt @@ -0,0 +1,18 @@ +--TEST-- +Immediate static method call on new object with ctor parentheses +--FILE-- + +--EXPECTF-- +Parse error: syntax error, unexpected identifier "test", expecting variable or "$" in %s on line %d diff --git a/Zend/tests/new_obj_access_without_parentheses/new_class_no_ctor_parentheses_static_property.phpt b/Zend/tests/new_obj_access_without_parentheses/new_class_no_ctor_parentheses_static_property.phpt new file mode 100644 index 0000000000000..8ffd731f3b708 --- /dev/null +++ b/Zend/tests/new_obj_access_without_parentheses/new_class_no_ctor_parentheses_static_property.phpt @@ -0,0 +1,20 @@ +--TEST-- +Immediate static property access on new object with ctor parentheses +--FILE-- + +--EXPECT-- +object(B)#1 (0) { +} From a9c3892f5cc20770edd037e89c23a6da1ef9229c Mon Sep 17 00:00:00 2001 From: Valentin Udaltsov Date: Mon, 8 Apr 2024 10:14:25 +0300 Subject: [PATCH 07/11] Add garbage collection test --- .../gc.phpt | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Zend/tests/new_obj_access_without_parentheses/gc.phpt diff --git a/Zend/tests/new_obj_access_without_parentheses/gc.phpt b/Zend/tests/new_obj_access_without_parentheses/gc.phpt new file mode 100644 index 0000000000000..4b7c7733a5e59 --- /dev/null +++ b/Zend/tests/new_obj_access_without_parentheses/gc.phpt @@ -0,0 +1,26 @@ +--TEST-- +Object instantiated without parentheses is collected +--FILE-- +test(); +echo 'code after' . PHP_EOL; + +?> +--EXPECT-- +called +collected +code after From 1289eecbac9802ececf2b15ad6030096f1d27a0c Mon Sep 17 00:00:00 2001 From: Valentin Udaltsov Date: Tue, 9 Apr 2024 08:27:33 +0300 Subject: [PATCH 08/11] Add a test for a class and a function with the same name --- .../new_class_vs_function_with_same_name.phpt | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Zend/tests/new_obj_access_without_parentheses/new_class_vs_function_with_same_name.phpt diff --git a/Zend/tests/new_obj_access_without_parentheses/new_class_vs_function_with_same_name.phpt b/Zend/tests/new_obj_access_without_parentheses/new_class_vs_function_with_same_name.phpt new file mode 100644 index 0000000000000..0072c493c3d99 --- /dev/null +++ b/Zend/tests/new_obj_access_without_parentheses/new_class_vs_function_with_same_name.phpt @@ -0,0 +1,23 @@ +--TEST-- +A function and a class with the same name +--FILE-- + +--EXPECT-- +Another +object(Something)#1 (0) { +} +object(Another)#1 (0) { +} From 043231ac7449954dd683e02305effccd3b6a47fd Mon Sep 17 00:00:00 2001 From: Valentin Udaltsov Date: Sun, 26 May 2024 18:42:29 +0300 Subject: [PATCH 09/11] Add new_dereferenceable explicitly to other expressions instead of callable_variable --- Zend/zend_language_parser.y | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Zend/zend_language_parser.y b/Zend/zend_language_parser.y index 097ce789dc3b7..97ab2f68e00b7 100644 --- a/Zend/zend_language_parser.y +++ b/Zend/zend_language_parser.y @@ -1230,6 +1230,7 @@ expr: $$ = $2; if ($$->kind == ZEND_AST_CONDITIONAL) $$->attr = ZEND_PARENTHESIZED_CONDITIONAL; } + | new_dereferenceable { $$ = $1; } | new_non_dereferenceable { $$ = $1; } | expr '?' expr ':' expr { $$ = zend_ast_create(ZEND_AST_CONDITIONAL, $1, $3, $5); } @@ -1329,6 +1330,8 @@ function_call: { $$ = zend_ast_create(ZEND_AST_STATIC_CALL, $1, $3, $4); } | variable_class_name T_PAAMAYIM_NEKUDOTAYIM member_name argument_list { $$ = zend_ast_create(ZEND_AST_STATIC_CALL, $1, $3, $4); } + | new_dereferenceable T_PAAMAYIM_NEKUDOTAYIM member_name argument_list + { $$ = zend_ast_create(ZEND_AST_STATIC_CALL, $1, $3, $4); } | callable_expr { $$ = CG(zend_lineno); } argument_list { $$ = zend_ast_create(ZEND_AST_CALL, $1, $3); $$->lineno = $2; @@ -1403,10 +1406,14 @@ class_constant: { $$ = zend_ast_create_class_const_or_name($1, $3); } | variable_class_name T_PAAMAYIM_NEKUDOTAYIM identifier { $$ = zend_ast_create_class_const_or_name($1, $3); } + | new_dereferenceable T_PAAMAYIM_NEKUDOTAYIM identifier + { $$ = zend_ast_create_class_const_or_name($1, $3); } | class_name T_PAAMAYIM_NEKUDOTAYIM '{' expr '}' { $$ = zend_ast_create(ZEND_AST_CLASS_CONST, $1, $4); } | variable_class_name T_PAAMAYIM_NEKUDOTAYIM '{' expr '}' { $$ = zend_ast_create(ZEND_AST_CLASS_CONST, $1, $4); } + | new_dereferenceable T_PAAMAYIM_NEKUDOTAYIM '{' expr '}' + { $$ = zend_ast_create(ZEND_AST_CLASS_CONST, $1, $4); } ; optional_expr: @@ -1428,12 +1435,14 @@ fully_dereferenceable: array_object_dereferenceable: fully_dereferenceable { $$ = $1; } | constant { $$ = $1; } + | new_dereferenceable { $$ = $1; } ; callable_expr: callable_variable { $$ = $1; } | '(' expr ')' { $$ = $2; } | dereferenceable_scalar { $$ = $1; } + | new_dereferenceable { $$ = $1; } ; callable_variable: @@ -1448,7 +1457,6 @@ callable_variable: | array_object_dereferenceable T_NULLSAFE_OBJECT_OPERATOR property_name argument_list { $$ = zend_ast_create(ZEND_AST_NULLSAFE_METHOD_CALL, $1, $3, $4); } | function_call { $$ = $1; } - | new_dereferenceable { $$ = $1; } ; variable: @@ -1473,6 +1481,8 @@ static_member: { $$ = zend_ast_create(ZEND_AST_STATIC_PROP, $1, $3); } | variable_class_name T_PAAMAYIM_NEKUDOTAYIM simple_variable { $$ = zend_ast_create(ZEND_AST_STATIC_PROP, $1, $3); } + | new_dereferenceable T_PAAMAYIM_NEKUDOTAYIM simple_variable + { $$ = zend_ast_create(ZEND_AST_STATIC_PROP, $1, $3); } ; new_variable: From d8ef6d59d31fd3fe71a2e039fa8ada406f709ed1 Mon Sep 17 00:00:00 2001 From: Valentin Udaltsov Date: Sun, 26 May 2024 17:25:05 +0300 Subject: [PATCH 10/11] Refactor tests --- .../new_anonymous_constant.phpt | 12 -- .../new_anonymous_invoke.phpt | 15 --- .../new_anonymous_method.phpt | 15 --- .../new_anonymous_property.phpt | 12 -- .../new_anonymous_static_method.phpt | 15 --- .../new_anonymous_static_property.phpt | 12 -- .../new_class_constant.phpt | 15 --- .../new_class_invoke.phpt | 18 --- .../new_class_method.phpt | 18 --- .../new_class_property.phpt | 15 --- .../new_class_static_method.phpt | 18 --- .../new_class_static_property.phpt | 15 --- .../new_expr_constant.phpt | 15 --- .../new_expr_invoke.phpt | 18 --- .../new_expr_method.phpt | 18 --- .../new_expr_property.phpt | 15 --- .../new_expr_static_method.phpt | 18 --- .../new_expr_static_property.phpt | 15 --- .../new_var_constant.phpt | 17 --- .../new_var_invoke.phpt | 20 ---- .../new_var_method.phpt | 20 ---- .../new_var_property.phpt | 17 --- .../new_var_static_method.phpt | 20 ---- .../new_var_static_property.phpt | 17 --- .../anonymous_class_access.phpt | 64 ++++++++++ .../assign_to_new.phpt | 10 ++ .../garbage_collection.phpt} | 0 .../new_class_vs_function_with_same_name.phpt | 4 +- .../new_with_ctor_arguments_parentheses.phpt | 111 ++++++++++++++++++ ...or_arguments_parentheses_array_access.phpt | 14 +++ ..._ctor_arguments_parentheses_constant.phpt} | 2 +- ...ut_ctor_arguments_parentheses_method.phpt} | 2 +- ..._ctor_arguments_parentheses_property.phpt} | 2 +- ..._arguments_parentheses_static_method.phpt} | 2 +- ...rguments_parentheses_static_property.phpt} | 2 +- .../new_without_parentheses/unset_new.phpt | 10 ++ 36 files changed, 217 insertions(+), 396 deletions(-) delete mode 100644 Zend/tests/new_obj_access_without_parentheses/new_anonymous_constant.phpt delete mode 100644 Zend/tests/new_obj_access_without_parentheses/new_anonymous_invoke.phpt delete mode 100644 Zend/tests/new_obj_access_without_parentheses/new_anonymous_method.phpt delete mode 100644 Zend/tests/new_obj_access_without_parentheses/new_anonymous_property.phpt delete mode 100644 Zend/tests/new_obj_access_without_parentheses/new_anonymous_static_method.phpt delete mode 100644 Zend/tests/new_obj_access_without_parentheses/new_anonymous_static_property.phpt delete mode 100644 Zend/tests/new_obj_access_without_parentheses/new_class_constant.phpt delete mode 100644 Zend/tests/new_obj_access_without_parentheses/new_class_invoke.phpt delete mode 100644 Zend/tests/new_obj_access_without_parentheses/new_class_method.phpt delete mode 100644 Zend/tests/new_obj_access_without_parentheses/new_class_property.phpt delete mode 100644 Zend/tests/new_obj_access_without_parentheses/new_class_static_method.phpt delete mode 100644 Zend/tests/new_obj_access_without_parentheses/new_class_static_property.phpt delete mode 100644 Zend/tests/new_obj_access_without_parentheses/new_expr_constant.phpt delete mode 100644 Zend/tests/new_obj_access_without_parentheses/new_expr_invoke.phpt delete mode 100644 Zend/tests/new_obj_access_without_parentheses/new_expr_method.phpt delete mode 100644 Zend/tests/new_obj_access_without_parentheses/new_expr_property.phpt delete mode 100644 Zend/tests/new_obj_access_without_parentheses/new_expr_static_method.phpt delete mode 100644 Zend/tests/new_obj_access_without_parentheses/new_expr_static_property.phpt delete mode 100644 Zend/tests/new_obj_access_without_parentheses/new_var_constant.phpt delete mode 100644 Zend/tests/new_obj_access_without_parentheses/new_var_invoke.phpt delete mode 100644 Zend/tests/new_obj_access_without_parentheses/new_var_method.phpt delete mode 100644 Zend/tests/new_obj_access_without_parentheses/new_var_property.phpt delete mode 100644 Zend/tests/new_obj_access_without_parentheses/new_var_static_method.phpt delete mode 100644 Zend/tests/new_obj_access_without_parentheses/new_var_static_property.phpt create mode 100644 Zend/tests/new_without_parentheses/anonymous_class_access.phpt create mode 100644 Zend/tests/new_without_parentheses/assign_to_new.phpt rename Zend/tests/{new_obj_access_without_parentheses/gc.phpt => new_without_parentheses/garbage_collection.phpt} (100%) rename Zend/tests/{new_obj_access_without_parentheses => new_without_parentheses}/new_class_vs_function_with_same_name.phpt (82%) create mode 100644 Zend/tests/new_without_parentheses/new_with_ctor_arguments_parentheses.phpt create mode 100644 Zend/tests/new_without_parentheses/new_without_ctor_arguments_parentheses_array_access.phpt rename Zend/tests/{new_obj_access_without_parentheses/new_class_no_ctor_parentheses_constant.phpt => new_without_parentheses/new_without_ctor_arguments_parentheses_constant.phpt} (72%) rename Zend/tests/{new_obj_access_without_parentheses/new_class_no_ctor_parentheses_method.phpt => new_without_parentheses/new_without_ctor_arguments_parentheses_method.phpt} (74%) rename Zend/tests/{new_obj_access_without_parentheses/new_class_no_ctor_parentheses_property.phpt => new_without_parentheses/new_without_ctor_arguments_parentheses_property.phpt} (72%) rename Zend/tests/{new_obj_access_without_parentheses/new_class_no_ctor_parentheses_static_method.phpt => new_without_parentheses/new_without_ctor_arguments_parentheses_static_method.phpt} (76%) rename Zend/tests/{new_obj_access_without_parentheses/new_class_no_ctor_parentheses_static_property.phpt => new_without_parentheses/new_without_ctor_arguments_parentheses_static_property.phpt} (64%) create mode 100644 Zend/tests/new_without_parentheses/unset_new.phpt diff --git a/Zend/tests/new_obj_access_without_parentheses/new_anonymous_constant.phpt b/Zend/tests/new_obj_access_without_parentheses/new_anonymous_constant.phpt deleted file mode 100644 index ee87e0b550f2a..0000000000000 --- a/Zend/tests/new_obj_access_without_parentheses/new_anonymous_constant.phpt +++ /dev/null @@ -1,12 +0,0 @@ ---TEST-- -Immediate constant access on new anonymous class object ---FILE-- - ---EXPECT-- -constant diff --git a/Zend/tests/new_obj_access_without_parentheses/new_anonymous_invoke.phpt b/Zend/tests/new_obj_access_without_parentheses/new_anonymous_invoke.phpt deleted file mode 100644 index 963c39ae31488..0000000000000 --- a/Zend/tests/new_obj_access_without_parentheses/new_anonymous_invoke.phpt +++ /dev/null @@ -1,15 +0,0 @@ ---TEST-- -Immediate invocation of new anonymous class object ---FILE-- - ---EXPECT-- -invoked diff --git a/Zend/tests/new_obj_access_without_parentheses/new_anonymous_method.phpt b/Zend/tests/new_obj_access_without_parentheses/new_anonymous_method.phpt deleted file mode 100644 index 133436600139d..0000000000000 --- a/Zend/tests/new_obj_access_without_parentheses/new_anonymous_method.phpt +++ /dev/null @@ -1,15 +0,0 @@ ---TEST-- -Immediate method call on new anonymous class object ---FILE-- -test(); - -?> ---EXPECT-- -called diff --git a/Zend/tests/new_obj_access_without_parentheses/new_anonymous_property.phpt b/Zend/tests/new_obj_access_without_parentheses/new_anonymous_property.phpt deleted file mode 100644 index 33c652c943308..0000000000000 --- a/Zend/tests/new_obj_access_without_parentheses/new_anonymous_property.phpt +++ /dev/null @@ -1,12 +0,0 @@ ---TEST-- -Immediate property access on new anonymous class object ---FILE-- -property; - -?> ---EXPECT-- -property diff --git a/Zend/tests/new_obj_access_without_parentheses/new_anonymous_static_method.phpt b/Zend/tests/new_obj_access_without_parentheses/new_anonymous_static_method.phpt deleted file mode 100644 index 1a37317023811..0000000000000 --- a/Zend/tests/new_obj_access_without_parentheses/new_anonymous_static_method.phpt +++ /dev/null @@ -1,15 +0,0 @@ ---TEST-- -Immediate static method call on new anonymous class object ---FILE-- - ---EXPECT-- -called diff --git a/Zend/tests/new_obj_access_without_parentheses/new_anonymous_static_property.phpt b/Zend/tests/new_obj_access_without_parentheses/new_anonymous_static_property.phpt deleted file mode 100644 index 0027f1b629363..0000000000000 --- a/Zend/tests/new_obj_access_without_parentheses/new_anonymous_static_property.phpt +++ /dev/null @@ -1,12 +0,0 @@ ---TEST-- -Immediate static property access on new anonymous class object ---FILE-- - ---EXPECT-- -staticProperty diff --git a/Zend/tests/new_obj_access_without_parentheses/new_class_constant.phpt b/Zend/tests/new_obj_access_without_parentheses/new_class_constant.phpt deleted file mode 100644 index 082a9d5211824..0000000000000 --- a/Zend/tests/new_obj_access_without_parentheses/new_class_constant.phpt +++ /dev/null @@ -1,15 +0,0 @@ ---TEST-- -Immediate constant access on new object with ctor parentheses ---FILE-- - ---EXPECT-- -constant diff --git a/Zend/tests/new_obj_access_without_parentheses/new_class_invoke.phpt b/Zend/tests/new_obj_access_without_parentheses/new_class_invoke.phpt deleted file mode 100644 index 8bf8cd88c42e5..0000000000000 --- a/Zend/tests/new_obj_access_without_parentheses/new_class_invoke.phpt +++ /dev/null @@ -1,18 +0,0 @@ ---TEST-- -Immediate invocation of new object with ctor parentheses ---FILE-- - ---EXPECT-- -invoked diff --git a/Zend/tests/new_obj_access_without_parentheses/new_class_method.phpt b/Zend/tests/new_obj_access_without_parentheses/new_class_method.phpt deleted file mode 100644 index afd72fea297a2..0000000000000 --- a/Zend/tests/new_obj_access_without_parentheses/new_class_method.phpt +++ /dev/null @@ -1,18 +0,0 @@ ---TEST-- -Immediate method call on new object with ctor parentheses ---FILE-- -test(); - -?> ---EXPECT-- -called diff --git a/Zend/tests/new_obj_access_without_parentheses/new_class_property.phpt b/Zend/tests/new_obj_access_without_parentheses/new_class_property.phpt deleted file mode 100644 index ce456aaea612b..0000000000000 --- a/Zend/tests/new_obj_access_without_parentheses/new_class_property.phpt +++ /dev/null @@ -1,15 +0,0 @@ ---TEST-- -Immediate property access on new object with ctor parentheses ---FILE-- -prop; - -?> ---EXPECT-- -property diff --git a/Zend/tests/new_obj_access_without_parentheses/new_class_static_method.phpt b/Zend/tests/new_obj_access_without_parentheses/new_class_static_method.phpt deleted file mode 100644 index 25250dc43f6d0..0000000000000 --- a/Zend/tests/new_obj_access_without_parentheses/new_class_static_method.phpt +++ /dev/null @@ -1,18 +0,0 @@ ---TEST-- -Immediate static method call on new object with ctor parentheses ---FILE-- - ---EXPECT-- -called diff --git a/Zend/tests/new_obj_access_without_parentheses/new_class_static_property.phpt b/Zend/tests/new_obj_access_without_parentheses/new_class_static_property.phpt deleted file mode 100644 index ac96bd43e0c7b..0000000000000 --- a/Zend/tests/new_obj_access_without_parentheses/new_class_static_property.phpt +++ /dev/null @@ -1,15 +0,0 @@ ---TEST-- -Immediate static property access on new object with ctor parentheses ---FILE-- - ---EXPECT-- -property diff --git a/Zend/tests/new_obj_access_without_parentheses/new_expr_constant.phpt b/Zend/tests/new_obj_access_without_parentheses/new_expr_constant.phpt deleted file mode 100644 index 90ceaf60b6db9..0000000000000 --- a/Zend/tests/new_obj_access_without_parentheses/new_expr_constant.phpt +++ /dev/null @@ -1,15 +0,0 @@ ---TEST-- -Immediate constant access on new object with ctor parentheses created from expr ---FILE-- - ---EXPECT-- -constant diff --git a/Zend/tests/new_obj_access_without_parentheses/new_expr_invoke.phpt b/Zend/tests/new_obj_access_without_parentheses/new_expr_invoke.phpt deleted file mode 100644 index 39bc737ad48c0..0000000000000 --- a/Zend/tests/new_obj_access_without_parentheses/new_expr_invoke.phpt +++ /dev/null @@ -1,18 +0,0 @@ ---TEST-- -Immediate invocation of new object with ctor parentheses created from expr ---FILE-- - ---EXPECT-- -invoked diff --git a/Zend/tests/new_obj_access_without_parentheses/new_expr_method.phpt b/Zend/tests/new_obj_access_without_parentheses/new_expr_method.phpt deleted file mode 100644 index 09e8bea4c77d0..0000000000000 --- a/Zend/tests/new_obj_access_without_parentheses/new_expr_method.phpt +++ /dev/null @@ -1,18 +0,0 @@ ---TEST-- -Immediate method call on new object with ctor parentheses created from expr ---FILE-- -test(); - -?> ---EXPECT-- -called diff --git a/Zend/tests/new_obj_access_without_parentheses/new_expr_property.phpt b/Zend/tests/new_obj_access_without_parentheses/new_expr_property.phpt deleted file mode 100644 index b3c952aae2f6c..0000000000000 --- a/Zend/tests/new_obj_access_without_parentheses/new_expr_property.phpt +++ /dev/null @@ -1,15 +0,0 @@ ---TEST-- -Immediate property access on new object with ctor parentheses created from expr ---FILE-- -prop; - -?> ---EXPECT-- -property diff --git a/Zend/tests/new_obj_access_without_parentheses/new_expr_static_method.phpt b/Zend/tests/new_obj_access_without_parentheses/new_expr_static_method.phpt deleted file mode 100644 index 3a30ab4f77aac..0000000000000 --- a/Zend/tests/new_obj_access_without_parentheses/new_expr_static_method.phpt +++ /dev/null @@ -1,18 +0,0 @@ ---TEST-- -Immediate static method call on new object with ctor parentheses created from expr ---FILE-- - ---EXPECT-- -called diff --git a/Zend/tests/new_obj_access_without_parentheses/new_expr_static_property.phpt b/Zend/tests/new_obj_access_without_parentheses/new_expr_static_property.phpt deleted file mode 100644 index 6aad5fdbd701d..0000000000000 --- a/Zend/tests/new_obj_access_without_parentheses/new_expr_static_property.phpt +++ /dev/null @@ -1,15 +0,0 @@ ---TEST-- -Immediate static property access on new object with ctor parentheses created from expr ---FILE-- - ---EXPECT-- -property diff --git a/Zend/tests/new_obj_access_without_parentheses/new_var_constant.phpt b/Zend/tests/new_obj_access_without_parentheses/new_var_constant.phpt deleted file mode 100644 index 09dbe4b4b29bf..0000000000000 --- a/Zend/tests/new_obj_access_without_parentheses/new_var_constant.phpt +++ /dev/null @@ -1,17 +0,0 @@ ---TEST-- -Immediate constant access on new object with ctor parentheses created from var ---FILE-- - ---EXPECT-- -constant diff --git a/Zend/tests/new_obj_access_without_parentheses/new_var_invoke.phpt b/Zend/tests/new_obj_access_without_parentheses/new_var_invoke.phpt deleted file mode 100644 index 52e88a57113da..0000000000000 --- a/Zend/tests/new_obj_access_without_parentheses/new_var_invoke.phpt +++ /dev/null @@ -1,20 +0,0 @@ ---TEST-- -Immediate invocation of new object with ctor parentheses created from var ---FILE-- - ---EXPECT-- -invoked diff --git a/Zend/tests/new_obj_access_without_parentheses/new_var_method.phpt b/Zend/tests/new_obj_access_without_parentheses/new_var_method.phpt deleted file mode 100644 index c7f67cbceb8fa..0000000000000 --- a/Zend/tests/new_obj_access_without_parentheses/new_var_method.phpt +++ /dev/null @@ -1,20 +0,0 @@ ---TEST-- -Immediate method call on new object with ctor parentheses created from var ---FILE-- -test(); - -?> ---EXPECT-- -called diff --git a/Zend/tests/new_obj_access_without_parentheses/new_var_property.phpt b/Zend/tests/new_obj_access_without_parentheses/new_var_property.phpt deleted file mode 100644 index e2f9b37342a00..0000000000000 --- a/Zend/tests/new_obj_access_without_parentheses/new_var_property.phpt +++ /dev/null @@ -1,17 +0,0 @@ ---TEST-- -Immediate property access on new object with ctor parentheses created from var ---FILE-- -prop; - -?> ---EXPECT-- -property diff --git a/Zend/tests/new_obj_access_without_parentheses/new_var_static_method.phpt b/Zend/tests/new_obj_access_without_parentheses/new_var_static_method.phpt deleted file mode 100644 index 89511f0277ab1..0000000000000 --- a/Zend/tests/new_obj_access_without_parentheses/new_var_static_method.phpt +++ /dev/null @@ -1,20 +0,0 @@ ---TEST-- -Immediate static method call on new object with ctor parentheses created from var ---FILE-- - ---EXPECT-- -called diff --git a/Zend/tests/new_obj_access_without_parentheses/new_var_static_property.phpt b/Zend/tests/new_obj_access_without_parentheses/new_var_static_property.phpt deleted file mode 100644 index 22d2c893ddb27..0000000000000 --- a/Zend/tests/new_obj_access_without_parentheses/new_var_static_property.phpt +++ /dev/null @@ -1,17 +0,0 @@ ---TEST-- -Immediate static property access on new object with ctor parentheses created from var ---FILE-- - ---EXPECT-- -property diff --git a/Zend/tests/new_without_parentheses/anonymous_class_access.phpt b/Zend/tests/new_without_parentheses/anonymous_class_access.phpt new file mode 100644 index 0000000000000..326f6cd25392b --- /dev/null +++ b/Zend/tests/new_without_parentheses/anonymous_class_access.phpt @@ -0,0 +1,64 @@ +--TEST-- +Immediate access on new anonymous class +--FILE-- +property; + +echo new class { + public static $property = 'static property' . PHP_EOL; +}::$property; + +new class { + public function method() { echo 'method' . PHP_EOL; } +}->method(); + +new class { + public static function method() { echo 'static method' . PHP_EOL; } +}::method(); + +new class { + public function __invoke() { echo '__invoke' . PHP_EOL; } +}(); + +new class () implements ArrayAccess { + public function offsetExists(mixed $offset): bool { return true; } + + public function offsetGet(mixed $offset): mixed { echo 'offsetGet' . PHP_EOL; return null; } + + public function offsetSet(mixed $offset, mixed $value): void {} + + public function offsetUnset(mixed $offset): void {} +}['key']; + +isset(new class () implements ArrayAccess { + public function offsetExists(mixed $offset): bool { echo 'offsetExists' . PHP_EOL; return true; } + + public function offsetGet(mixed $offset): mixed { return null; } + + public function offsetSet(mixed $offset, mixed $value): void {} + + public function offsetUnset(mixed $offset): void {} +}['key']); + +?> +--EXPECT-- +constant +constant +property +static property +method +static method +__invoke +offsetGet +offsetExists diff --git a/Zend/tests/new_without_parentheses/assign_to_new.phpt b/Zend/tests/new_without_parentheses/assign_to_new.phpt new file mode 100644 index 0000000000000..bee87457a1e3c --- /dev/null +++ b/Zend/tests/new_without_parentheses/assign_to_new.phpt @@ -0,0 +1,10 @@ +--TEST-- +Cannot assign to new expression +--FILE-- + +--EXPECTF-- +Parse error: syntax error, unexpected token "=" in %s on line %d diff --git a/Zend/tests/new_obj_access_without_parentheses/gc.phpt b/Zend/tests/new_without_parentheses/garbage_collection.phpt similarity index 100% rename from Zend/tests/new_obj_access_without_parentheses/gc.phpt rename to Zend/tests/new_without_parentheses/garbage_collection.phpt diff --git a/Zend/tests/new_obj_access_without_parentheses/new_class_vs_function_with_same_name.phpt b/Zend/tests/new_without_parentheses/new_class_vs_function_with_same_name.phpt similarity index 82% rename from Zend/tests/new_obj_access_without_parentheses/new_class_vs_function_with_same_name.phpt rename to Zend/tests/new_without_parentheses/new_class_vs_function_with_same_name.phpt index 0072c493c3d99..cd3161e15b939 100644 --- a/Zend/tests/new_obj_access_without_parentheses/new_class_vs_function_with_same_name.phpt +++ b/Zend/tests/new_without_parentheses/new_class_vs_function_with_same_name.phpt @@ -1,5 +1,5 @@ --TEST-- -A function and a class with the same name +A function and a class with the same name work as expected --FILE-- property; +echo new $class()->property; +echo new (trim(' A '))()->property; + +echo new A()::$staticProperty; +echo new $class()::$staticProperty; +echo new (trim(' A '))()::$staticProperty; + +new A()(); +new $class()(); +new (trim(' A '))()(); + +new A()->method(); +new $class()->method(); +new (trim(' A '))()->method(); + +new A()::staticMethod(); +new $class()::staticMethod(); +new (trim(' A '))()::staticMethod(); + +new A()['key']; +new $class()['key']; +new (trim(' A '))()['key']; + +isset(new A()['key']); +isset(new $class()['key']); +isset(new (trim(' A '))()['key']); + +?> +--EXPECT-- +constant +constant +constant +constant +constant +constant +property +property +property +static property +static property +static property +__invoke +__invoke +__invoke +method +method +method +static method +static method +static method +offsetGet +offsetGet +offsetGet +offsetExists +offsetExists +offsetExists diff --git a/Zend/tests/new_without_parentheses/new_without_ctor_arguments_parentheses_array_access.phpt b/Zend/tests/new_without_parentheses/new_without_ctor_arguments_parentheses_array_access.phpt new file mode 100644 index 0000000000000..5d93ea1f34ac6 --- /dev/null +++ b/Zend/tests/new_without_parentheses/new_without_ctor_arguments_parentheses_array_access.phpt @@ -0,0 +1,14 @@ +--TEST-- +Immediate array access on new object without constructor parentheses +--FILE-- + +--EXPECTF-- +Parse error: syntax error, unexpected token "[", expecting "," or ";" in %s on line %d diff --git a/Zend/tests/new_obj_access_without_parentheses/new_class_no_ctor_parentheses_constant.phpt b/Zend/tests/new_without_parentheses/new_without_ctor_arguments_parentheses_constant.phpt similarity index 72% rename from Zend/tests/new_obj_access_without_parentheses/new_class_no_ctor_parentheses_constant.phpt rename to Zend/tests/new_without_parentheses/new_without_ctor_arguments_parentheses_constant.phpt index a1085b81558c4..27b9697da1793 100644 --- a/Zend/tests/new_obj_access_without_parentheses/new_class_no_ctor_parentheses_constant.phpt +++ b/Zend/tests/new_without_parentheses/new_without_ctor_arguments_parentheses_constant.phpt @@ -1,5 +1,5 @@ --TEST-- -Immediate constant access on new object with ctor parentheses +Immediate constant access on new object without constructor parentheses --FILE-- +--EXPECTF-- +Parse error: syntax error, unexpected token ")", expecting "->" or "?->" or "{" or "[" in %s on line %d From f3b54d5a72b4c7189b88027366c33151955c2795 Mon Sep 17 00:00:00 2001 From: Valentin Udaltsov Date: Mon, 27 May 2024 06:06:26 +0300 Subject: [PATCH 11/11] Use new_dereferenceable in fully_dereferenceable and callable_expr only --- Zend/zend_language_parser.y | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/Zend/zend_language_parser.y b/Zend/zend_language_parser.y index 97ab2f68e00b7..748c8a8862791 100644 --- a/Zend/zend_language_parser.y +++ b/Zend/zend_language_parser.y @@ -1330,8 +1330,6 @@ function_call: { $$ = zend_ast_create(ZEND_AST_STATIC_CALL, $1, $3, $4); } | variable_class_name T_PAAMAYIM_NEKUDOTAYIM member_name argument_list { $$ = zend_ast_create(ZEND_AST_STATIC_CALL, $1, $3, $4); } - | new_dereferenceable T_PAAMAYIM_NEKUDOTAYIM member_name argument_list - { $$ = zend_ast_create(ZEND_AST_STATIC_CALL, $1, $3, $4); } | callable_expr { $$ = CG(zend_lineno); } argument_list { $$ = zend_ast_create(ZEND_AST_CALL, $1, $3); $$->lineno = $2; @@ -1406,14 +1404,10 @@ class_constant: { $$ = zend_ast_create_class_const_or_name($1, $3); } | variable_class_name T_PAAMAYIM_NEKUDOTAYIM identifier { $$ = zend_ast_create_class_const_or_name($1, $3); } - | new_dereferenceable T_PAAMAYIM_NEKUDOTAYIM identifier - { $$ = zend_ast_create_class_const_or_name($1, $3); } | class_name T_PAAMAYIM_NEKUDOTAYIM '{' expr '}' { $$ = zend_ast_create(ZEND_AST_CLASS_CONST, $1, $4); } | variable_class_name T_PAAMAYIM_NEKUDOTAYIM '{' expr '}' { $$ = zend_ast_create(ZEND_AST_CLASS_CONST, $1, $4); } - | new_dereferenceable T_PAAMAYIM_NEKUDOTAYIM '{' expr '}' - { $$ = zend_ast_create(ZEND_AST_CLASS_CONST, $1, $4); } ; optional_expr: @@ -1430,12 +1424,12 @@ fully_dereferenceable: | '(' expr ')' { $$ = $2; } | dereferenceable_scalar { $$ = $1; } | class_constant { $$ = $1; } + | new_dereferenceable { $$ = $1; } ; array_object_dereferenceable: fully_dereferenceable { $$ = $1; } | constant { $$ = $1; } - | new_dereferenceable { $$ = $1; } ; callable_expr: @@ -1481,8 +1475,6 @@ static_member: { $$ = zend_ast_create(ZEND_AST_STATIC_PROP, $1, $3); } | variable_class_name T_PAAMAYIM_NEKUDOTAYIM simple_variable { $$ = zend_ast_create(ZEND_AST_STATIC_PROP, $1, $3); } - | new_dereferenceable T_PAAMAYIM_NEKUDOTAYIM simple_variable - { $$ = zend_ast_create(ZEND_AST_STATIC_PROP, $1, $3); } ; new_variable: