Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for downgrading return type null #8324

Closed
RikudouSage opened this issue Nov 24, 2023 · 6 comments · Fixed by rectorphp/rector-downgrade-php#208
Closed

Add support for downgrading return type null #8324

RikudouSage opened this issue Nov 24, 2023 · 6 comments · Fixed by rectorphp/rector-downgrade-php#208
Labels

Comments

@RikudouSage
Copy link

Feature Request

PHP 8.2 allows null to be used as a standalone return type.

Diff

Use case 1, without parent:

<?php

class WithoutParent
{
+    /**
+     * @return null
+     */
-    public function getSomething(): null
+    public function getSomething(): mixed
    {
    }
}

Use case 2, with a parent:

<?php

class ParentClass
{
    public function getSomeString(): ?string
    {
    }
}

class ChildClass extends ParentClass
{
+    /**
+     * @return null
+     */
-    public function getSomeString(): null
+    public function getSomeString(): ?string
    {
    }
}
@TomasVotruba
Copy link
Member

Hi, thanks for proposal. We actually don't support docblock-based types since Rector 0.15 https://getrector.com/blog/new-in-rector-015-complete-safe-and-known-type-declarations as it lead to false positive and breaking code in the past.

We infer return/param/property type declarations from the code itself instead as the only safe way.

Use the TYPE_DECLARATIONS set instead 👍

@RikudouSage
Copy link
Author

How does that help? This is a downgrade rector that downgrades unsupported features from php 8.2. Meaning if someone imports the downgrade set, it should downgrade everything it can to supported syntax.

@TomasVotruba
Copy link
Member

Ah, I confused the change other way around, my bad.

That would be great addition. Could you open up PR?

@samsonasik samsonasik reopened this Nov 24, 2023
@TomasVotruba
Copy link
Member

@samsonasik Could you add this rule to the PHP 8.2 set?

@samsonasik
Copy link
Member

I will try

@samsonasik
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants