You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PHP 8.4 | Tokenizer/PHP: allow for anon class dereferencing
As of PHP 8.4, new expressions can be dereferenced without needing parentheses wrappers, as long as they have the parentheses for the constructor arguments.
```php
echo new MyClass()->property;
echo new $myClass(['value'])[0];
```
Additionally, new expressions involving anonymous classes can also be dereferenced directly and these do not have the constructor argument parentheses requirement.
```php
echo new class { public $property = 'property'; }->property;
echo new class (['value']) extends ArrayObject {}[0];
```
For the most part, this has no impact on the PHPCS tokenizer layer, however, dereferencing the result of a new anonymous class expression using array access runs into trouble with the short array retokenization.
I.e. the square brackets in the below example were tokenized as `T_OPEN|CLOSE_SHORT_ARRAY`, while they should be tokenized as `T_OPEN|CLOSE_SQUARE_BRACKET`.
```php
echo new class {}[0];
```
Fixed now. Includes tests safeguarding the fix.
Refs:
* https://wiki.php.net/rfc/new_without_parentheses
* php/php-src 13029
0 commit comments