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

Array after typecasting does not count as array #5834

Closed
Anamelash opened this issue Oct 25, 2021 · 2 comments
Closed

Array after typecasting does not count as array #5834

Anamelash opened this issue Oct 25, 2021 · 2 comments
Labels

Comments

@Anamelash
Copy link

Anamelash commented Oct 25, 2021

Bug report

<?php declare(strict_types = 1);

class Bar
{
	/** 
	* @var array|mixed|null
	*/
	private $bar = null;
	
	/**
	* @return array|mixed|null
	*/
	public function getBar()
	{
		return $this->bar;
	}
}

class Foo
{
	public function getFoo(Bar $bar): void
        {
            $array = (array) $bar->getBar();
            $statusCode = array_key_exists('key', $array) ? (string) $array['key'] : null;
	}
}
24 | Parameter #2 $array of function array_key_exists expects array, array given.

https://phpstan.org/r/e1579418-17bf-46dc-8c57-97e382ccde79

Obviously $array is array. But PhpStan thinks different (=

@phpstan-bot
Copy link
Contributor

@Anamelash After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-PHP 8.0 (1 error)
-==========
-
-24: Parameter #2 $array of function array_key_exists expects array, array given.
-
-PHP 7.1 – 7.4 (1 error)
-==========
-
-24: Parameter #2 $search of function array_key_exists expects array, array given.
+No errors

MidnightDesign pushed a commit to MidnightDesign/phpstan-src that referenced this issue Nov 30, 2021
@github-actions
Copy link

github-actions bot commented Dec 5, 2021

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants