Skip to content

Commit

Permalink
PHP 8.4 Support: new MyClass()->method() without parentheses (Part 6)
Browse files Browse the repository at this point in the history
  • Loading branch information
junichi11 committed Jan 6, 2025
1 parent 0875d01 commit cbb5c44
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
|-#anon#newWithoutParentheses_php#1 [846, 888] : ESCAPED{{}}
|--CONSTANT [864, 872] : ESCAPED{CONSTANT}ESCAPED{ }<font color="#999999">ESCAPED{'constant'}</font>
|-#anon#newWithoutParentheses_php#2 [910, 952] : ESCAPED{{}}
|--CONSTANT [928, 936] : ESCAPED{CONSTANT}ESCAPED{ }<font color="#999999">ESCAPED{'constant'}</font>
|-#anon#newWithoutParentheses_php#3 [978, 1016] : ESCAPED{{}}
|--$field [998, 1003] : ESCAPED{$field}
|-#anon#newWithoutParentheses_php#4 [1035, 1093] : ESCAPED{{}}
|--$staticField [1062, 1073] : ESCAPED{$staticField}
|-#anon#newWithoutParentheses_php#5 [1114, 1155] : ESCAPED{{}}
|--method [1142, 1153] : ESCAPED{method}ESCAPED{(}ESCAPED{)}
|-#anon#newWithoutParentheses_php#6 [1190, 1231] : ESCAPED{{}}
|--method [1218, 1229] : ESCAPED{method}ESCAPED{(}ESCAPED{)}
|-#anon#newWithoutParentheses_php#7 [1248, 1302] : ESCAPED{{}}
|--staticMethod [1283, 1300] : ESCAPED{staticMethod}ESCAPED{(}ESCAPED{)}
|-#anon#newWithoutParentheses_php#8 [1325, 1368] : ESCAPED{{}}
|--__invoke [1353, 1366] : ESCAPED{__invoke}ESCAPED{(}ESCAPED{)}
|-#anon#newWithoutParentheses_php#9 [1399, 1442] : ESCAPED{{}}
|--__invoke [1427, 1440] : ESCAPED{__invoke}ESCAPED{(}ESCAPED{)}
|-#anon#newWithoutParentheses_php#10 [1451, 1486] : ESCAPED{{}}
|-#anon#newWithoutParentheses_php#11 [1508, 1571] : ESCAPED{{}}
|--$field [1559, 1564] : ESCAPED{$field}<font color="#999999">:ESCAPED{int}</font>
|-#anon#newWithoutParentheses_php#12 [1591, 1639] : ESCAPED{{}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?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.
*/

// anonymous classes

echo new class {
const CONSTANT = 'constant';
}::CONSTANT;

echo new class {
const CONSTANT = 'constant';
}::{'CONSTANT'};

echo new class {
public $field = 'field';
}->field;

echo new class {
public static $staticField = 'static field';
}::$staticField;

new class {
public function method() {}
}->method();

$anon = new #[Attr()] class {
public function method() {}
}->method();

new class {
public static function staticMethod() {}
}::staticMethod();

new class {
public function __invoke() {}
}();

$anon = new #[Attr(1, 2)] class {
public function __invoke() {}
}();

new class () implements ArrayAccess {
}['key'];

$anon = new class () implements ArrayAccess {
private int $field = 1;
}['key'];

isset(new class ($a, 1, "test") implements ArrayAccess {
}['key']);
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,9 @@ public void testFunctionGuessingArrayReturnType() throws Exception {
public void testTypedClassConstants() throws Exception {
performTest("structure/php83/typedClassConstants");
}

// PHP 8.4
public void testNewWithoutParentheses() throws Exception {
performTest("structure/php84/newWithoutParentheses");
}
}

0 comments on commit cbb5c44

Please sign in to comment.