Skip to content

[DowngradePhp84] Handle property fetch, static access, array access and invocation on DowngradeNewMethodCallWithoutParenthesesRector - #424

Merged
TomasVotruba merged 1 commit into
mainfrom
downgrade-new-without-parentheses-all-dereferences
Nov 20, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
downgrade-new-without-parentheses-all-dereferences

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Counterpart of rectorphp/rector-src#9009.

DowngradeNewMethodCallWithoutParenthesesRector only handles MethodCall. PHP 8.4 also allows other dereferences on new without wrapping parentheses, and these stay unchanged, so the downgraded code does not parse on PHP 8.3 and lower:

$message = new Regex('some-pattern')->message;
new Request()?->withMethod('GET');
$constant = new Request()::METHOD_GET;
$value = new ArrayObject($items)['key'];
$result = new Invokable()();

The rule now also handles NullsafeMethodCall, PropertyFetch, NullsafePropertyFetch, StaticCall, StaticPropertyFetch, ClassConstFetch, ArrayDimFetch and FuncCall with a New_ name:

$message = (new Regex('some-pattern'))->message;
(new Request())?->withMethod('GET');
$constant = (new Request())::METHOD_GET;
$value = (new ArrayObject($items))['key'];
$result = (new Invokable())();

Added a fixture for each form, plus nested new and a skip fixture for already wrapped code. All fixture outputs pass php8.3 -l.

…nd invocation on DowngradeNewMethodCallWithoutParenthesesRector
@TomasVotruba
TomasVotruba merged commit 90b8e7c into main Nov 20, 2026
9 checks passed
@TomasVotruba
TomasVotruba deleted the downgrade-new-without-parentheses-all-dereferences branch November 20, 2026 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant