Skip to content

False positive: optional array keys and null coalescing operator #4926

@MidnightDesign

Description

@MidnightDesign

Bug report

Code snippet that reproduces the problem

https://phpstan.org/r/0499d145-4d75-4d7f-8e13-168d3562738c

<?php declare(strict_types = 1);

/**
 * @phpstan-type Data array{customer?: array{first_name: string}}
 */
class Foo
{
	/** @var Data */
	private array $data = [];
	
	public function getFirstName(): ?string
	{
		return $this->data['customer']['first_name'] ?? null;
	}
}

Expected output

No errors should be reported.

#3171 and #4592 are maybe related, but not exactly the same.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions