Skip to content

Conversation

@samsonasik
Copy link
Member

Given the following code:

class ReturnEmpty
{
   public function run(): array
    {
        return [];
    }
}

It currently got:

+   /**
+    * @return array<mixed, mixed>
+    */
    public function run(): array

which I think it can just:

@return mixed[]

@samsonasik
Copy link
Member Author

samsonasik commented Sep 12, 2025

Fixed with array<int, mixed>.

For note: the behaviour seems different with other rule that uses syntax: mixed[] over array<int, mixed>

The improvement next maybe if it only int key, should not use array<int, type> syntax, use direct type[] instead for consistency.

@samsonasik
Copy link
Member Author

All checks have passed 🎉 @TomasVotruba I am merging it ;)

@samsonasik samsonasik enabled auto-merge (squash) September 12, 2025 15:56
@samsonasik samsonasik merged commit ce2b370 into main Sep 12, 2025
48 of 49 checks passed
@samsonasik samsonasik deleted the mixed-mixed-empty branch September 12, 2025 15:57
@ruudk
Copy link
Contributor

ruudk commented Sep 13, 2025

Why return mixed[] for an empty array over array{}?

The array is empty and with array{} you say that it is.

@samsonasik
Copy link
Member Author

I just know that it can use empty @return array{}

https://phpstan.org/r/81019bab-b81f-4dd5-bf21-02bed1fca955

Let see if it can be improved next to that

@calebdw
Copy link
Contributor

calebdw commented Sep 13, 2025

The array key can never be mixed, at most it should be array-key

@samsonasik
Copy link
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants