Skip to content

Commit 00f65b8

Browse files
committed
PHP 8.4 Support: new MyClass()->method() without parentheses (Part 4)
- apache#8035 - https://wiki.php.net/rfc#php_84 - https://wiki.php.net/rfc/new_without_parentheses - Fix the `UnusedVariableHint` - Add a unit test
1 parent 6b32988 commit 00f65b8

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

php/php.editor/src/org/netbeans/modules/php/editor/verification/UnusedVariableHint.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,11 +671,12 @@ public void visit(ClassInstanceCreation node) {
671671
if (CancelSupport.getDefault().isCancelled()) {
672672
return;
673673
}
674+
boolean forceVariableAsUsedHolder = forceVariableAsUsed;
674675
forceVariableAsUsed = true;
675676
scan(node.getClassName());
676677
scan(node.ctorParams());
677678
scan(node.getBody());
678-
forceVariableAsUsed = false;
679+
forceVariableAsUsed = forceVariableAsUsedHolder;
679680
}
680681

681682
@Override
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
class Example {
21+
public static string $publicStaticField = "public static field";
22+
protected static string $protectedStaticField = "protected static field";
23+
private static string $privateStaticField = "private static field";
24+
25+
public function test1(): void {
26+
$example = new Example()::$publicStaticField;
27+
$example = new Example()::$protectedStaticField;
28+
$example = new Example()::$privateStaticField;
29+
}
30+
31+
public function test2(): void {
32+
$example = (new Example())::$publicStaticField;
33+
$example = (new Example())::$protectedStaticField;
34+
$example = (new Example())::$privateStaticField;
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

php/php.editor/test/unit/src/org/netbeans/modules/php/editor/verification/UnusedVariableHintTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ public void testConstructorPropertyPromotion_04() throws Exception {
114114
checkHints(new UnusedVariableHintStub(false, false), "testConstructorPropertyPromotion.php");
115115
}
116116

117+
public void testNewWithoutParentheses_01() throws Exception {
118+
checkHints(new UnusedVariableHintStub(false), "testNewWithoutParentheses.php");
119+
}
120+
117121
private class UnusedVariableHintStub extends UnusedVariableHint {
118122
private final boolean unusedFormalParameters;
119123
private final boolean inheritedMethodParameters;

0 commit comments

Comments
 (0)