Skip to content

Commit

Permalink
PHP 8.4 Support: new MyClass()->method() without parentheses (Part 4)
Browse files Browse the repository at this point in the history
  • Loading branch information
junichi11 committed Jan 6, 2025
1 parent 6b32988 commit 00f65b8
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -671,11 +671,12 @@ public void visit(ClassInstanceCreation node) {
if (CancelSupport.getDefault().isCancelled()) {
return;
}
boolean forceVariableAsUsedHolder = forceVariableAsUsed;
forceVariableAsUsed = true;
scan(node.getClassName());
scan(node.ctorParams());
scan(node.getBody());
forceVariableAsUsed = false;
forceVariableAsUsed = forceVariableAsUsedHolder;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
class Example {
public static string $publicStaticField = "public static field";
protected static string $protectedStaticField = "protected static field";
private static string $privateStaticField = "private static field";

public function test1(): void {
$example = new Example()::$publicStaticField;
$example = new Example()::$protectedStaticField;
$example = new Example()::$privateStaticField;
}

public function test2(): void {
$example = (new Example())::$publicStaticField;
$example = (new Example())::$protectedStaticField;
$example = (new Example())::$privateStaticField;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ public void testConstructorPropertyPromotion_04() throws Exception {
checkHints(new UnusedVariableHintStub(false, false), "testConstructorPropertyPromotion.php");
}

public void testNewWithoutParentheses_01() throws Exception {
checkHints(new UnusedVariableHintStub(false), "testNewWithoutParentheses.php");
}

private class UnusedVariableHintStub extends UnusedVariableHint {
private final boolean unusedFormalParameters;
private final boolean inheritedMethodParameters;
Expand Down

0 comments on commit 00f65b8

Please sign in to comment.