Skip to content

PHPStan sees another class HttpResponse than one in the actual source code #12151

@mikkorantalainen

Description

@mikkorantalainen

Bug report

PHPStan sees code from PECL library even if it's not used in reality. Example:

<?php
class HttpResponse
{
	/**
	 * Set entity tag (unique tag for this version) for this response
	 * @param int|string $etag the E-Tag value for this response
	 * @return void
	 */
	public function setEtag($etag)
	{
		printf("\"$etag\"\n");
	}
}

define("VERSION", 42);
$http = new HttpResponse();
$http->setETag(VERSION);

causes

Parameter #1 $etag of method HttpResponse::setEtag() expects string, int given. even though the setEtag() above clearly allows both int and string in the PhpDoc.

Code snippet that reproduces the problem

https://phpstan.org/r/00ba67d7-da6f-4382-9e7c-6c36e1ac4d61

Expected output

The above code should emit no errors or warnings.

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

PHPStan is a great tool to find potential issues in my code!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions