Skip to content

Array offset in OR condition can not be resolved. #6379

@janbarasek

Description

@janbarasek

Bug report

In case of code:

<?php declare(strict_types = 1);

class HelloWorld
{
	/**
	 * @param array{
	 *    cr?: string,
	 *    c?: string
	 * } $params
	 */
	public static function paramsToString(array $params): string
	{
		if (isset($params['cr']) === true || isset($params['c']) === true) {
			return sprintf('-c%s', $params['cr'] ?? $params['c']);
		}

		return '';
	}
}

PhpStan will report:

Offset 'c' does not exist on array{cr?: string, c?: string}.

Live example: https://phpstan.org/r/f10dbfb6-e501-41e8-8a37-aa9e9a61489b

Related to: #6377

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions