Skip to content

Single-quoted const string keys are treated differently to double-quoted const string keys #3474

@dktapps

Description

@dktapps

Bug report

checkExplicitMixed: true is required to reproduce this bug.

Code snippet that reproduces the problem

<?php

namespace test;

/**
 * @param mixed[] $a
 */
function acceptsArray(array $a) : void{

}

/**
 * @param mixed[] $a
 */
function dummy(array $a) : void{
	if(!is_array($a["test"])){
		throw new \RuntimeException("oops");
	}

	acceptsArray($a['test']);
}

Notice that the isset() uses a double-quoted key, while the acceptsArray() uses a single-quoted key.

phpstan.org doesn't have a checkExplicitMixed option, so it doesn't reproduce there: https://phpstan.org/r/7f09bc66-f22a-407b-a78d-d81dc1002d71

Expected output

No error should be produced.

Actual output

 ------ ---------------------------------------------------------------------------
  Line   Test.php
 ------ ---------------------------------------------------------------------------
  20     Parameter #1 $a of function test\acceptsArray expects array, mixed given.
 ------ ---------------------------------------------------------------------------

 [ERROR] Found 1 error

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions