Skip to content

Commit cbb5c44

Browse files
committed
PHP 8.4 Support: new MyClass()->method() without parentheses (Part 6)
- apache#8035 - https://wiki.php.net/rfc#php_84 - https://wiki.php.net/rfc/new_without_parentheses - Add a unit test for the navigator
1 parent 0875d01 commit cbb5c44

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
|-#anon#newWithoutParentheses_php#1 [846, 888] : ESCAPED{{}}
2+
|--CONSTANT [864, 872] : ESCAPED{CONSTANT}ESCAPED{ }<font color="#999999">ESCAPED{'constant'}</font>
3+
|-#anon#newWithoutParentheses_php#2 [910, 952] : ESCAPED{{}}
4+
|--CONSTANT [928, 936] : ESCAPED{CONSTANT}ESCAPED{ }<font color="#999999">ESCAPED{'constant'}</font>
5+
|-#anon#newWithoutParentheses_php#3 [978, 1016] : ESCAPED{{}}
6+
|--$field [998, 1003] : ESCAPED{$field}
7+
|-#anon#newWithoutParentheses_php#4 [1035, 1093] : ESCAPED{{}}
8+
|--$staticField [1062, 1073] : ESCAPED{$staticField}
9+
|-#anon#newWithoutParentheses_php#5 [1114, 1155] : ESCAPED{{}}
10+
|--method [1142, 1153] : ESCAPED{method}ESCAPED{(}ESCAPED{)}
11+
|-#anon#newWithoutParentheses_php#6 [1190, 1231] : ESCAPED{{}}
12+
|--method [1218, 1229] : ESCAPED{method}ESCAPED{(}ESCAPED{)}
13+
|-#anon#newWithoutParentheses_php#7 [1248, 1302] : ESCAPED{{}}
14+
|--staticMethod [1283, 1300] : ESCAPED{staticMethod}ESCAPED{(}ESCAPED{)}
15+
|-#anon#newWithoutParentheses_php#8 [1325, 1368] : ESCAPED{{}}
16+
|--__invoke [1353, 1366] : ESCAPED{__invoke}ESCAPED{(}ESCAPED{)}
17+
|-#anon#newWithoutParentheses_php#9 [1399, 1442] : ESCAPED{{}}
18+
|--__invoke [1427, 1440] : ESCAPED{__invoke}ESCAPED{(}ESCAPED{)}
19+
|-#anon#newWithoutParentheses_php#10 [1451, 1486] : ESCAPED{{}}
20+
|-#anon#newWithoutParentheses_php#11 [1508, 1571] : ESCAPED{{}}
21+
|--$field [1559, 1564] : ESCAPED{$field}<font color="#999999">:ESCAPED{int}</font>
22+
|-#anon#newWithoutParentheses_php#12 [1591, 1639] : ESCAPED{{}}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/*
3+
* Licensed to the Apache Software Foundation (ASF) under one
4+
* or more contributor license agreements. See the NOTICE file
5+
* distributed with this work for additional information
6+
* regarding copyright ownership. The ASF licenses this file
7+
* to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance
9+
* with the License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing,
14+
* software distributed under the License is distributed on an
15+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
* KIND, either express or implied. See the License for the
17+
* specific language governing permissions and limitations
18+
* under the License.
19+
*/
20+
21+
// anonymous classes
22+
23+
echo new class {
24+
const CONSTANT = 'constant';
25+
}::CONSTANT;
26+
27+
echo new class {
28+
const CONSTANT = 'constant';
29+
}::{'CONSTANT'};
30+
31+
echo new class {
32+
public $field = 'field';
33+
}->field;
34+
35+
echo new class {
36+
public static $staticField = 'static field';
37+
}::$staticField;
38+
39+
new class {
40+
public function method() {}
41+
}->method();
42+
43+
$anon = new #[Attr()] class {
44+
public function method() {}
45+
}->method();
46+
47+
new class {
48+
public static function staticMethod() {}
49+
}::staticMethod();
50+
51+
new class {
52+
public function __invoke() {}
53+
}();
54+
55+
$anon = new #[Attr(1, 2)] class {
56+
public function __invoke() {}
57+
}();
58+
59+
new class () implements ArrayAccess {
60+
}['key'];
61+
62+
$anon = new class () implements ArrayAccess {
63+
private int $field = 1;
64+
}['key'];
65+
66+
isset(new class ($a, 1, "test") implements ArrayAccess {
67+
}['key']);

php/php.editor/test/unit/src/org/netbeans/modules/php/editor/csl/NavigatorTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,9 @@ public void testFunctionGuessingArrayReturnType() throws Exception {
159159
public void testTypedClassConstants() throws Exception {
160160
performTest("structure/php83/typedClassConstants");
161161
}
162+
163+
// PHP 8.4
164+
public void testNewWithoutParentheses() throws Exception {
165+
performTest("structure/php84/newWithoutParentheses");
166+
}
162167
}

0 commit comments

Comments
 (0)