Skip to content

return type has no value type specified error although it is specified #12481

@nuryagdym

Description

@nuryagdym

Bug report

From the below code the return type of sayHello() is specified in HelloWorldInterface.
When child class returns array its format is array{abc: int};

<?php declare(strict_types = 1);

interface HelloWorldInterface
{
	/**
	 * @return array{abc: int}|string
	 */
	public function sayHello();
}

class HelloWorld implements HelloWorldInterface
{
	/**
	 * @inheritDoc
	 */
	public function sayHello(): array
	{
		return [
			"abc" => 1,
		];
	}
}

I don't get why it is complaining.

Code snippet that reproduces the problem

https://phpstan.org/r/bbaf4883-1af5-45d7-b38d-7567e32eef99

Expected output

No errors.

Did PHPStan help you today? Did it make you happy in any way?

Yes

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions