Skip to content

Conversation

@romm
Copy link

@romm romm commented Dec 5, 2020

The following code should not report an error anymore:

class SomeClass
{
	/**
	 * @param class-string $classString
	 */
	public function foo(string $classString): bool
	{
		return is_subclass_of(DateTimeInterface::class, $classString);
	}

	/**
	 * @param class-string<object> $classString
	 */
	public function bar(string $classString): bool
	{
		return is_subclass_of(DateTimeInterface::class, $classString);
	}
}

But this one will still report an error:

class SomeClass
{
	/**
	 * @param class-string<DateTimeInterface> $classString
	 */
	public function foo(string $classString): bool
	{
		return is_subclass_of(DateTimeInterface::class, $classString);
	}
}

Closes phpstan/phpstan#2755

@ondrejmirtes ondrejmirtes force-pushed the master branch 3 times, most recently from d45166a to 3526237 Compare December 12, 2020 10:56
The following code should not report an error anymore:

```php
class SomeClass
{
	/**
	 * @param class-string $classString
	 */
	public function foo(string $classString): bool
	{
		return is_subclass_of(DateTimeInterface::class, $classString);
	}

	/**
	 * @param class-string<object> $classString
	 */
	public function bar(string $classString): bool
	{
		return is_subclass_of(DateTimeInterface::class, $classString);
	}
}
```

But this one will still report an error:

```php
class SomeClass
{
	/**
	 * @param class-string<DateTimeInterface> $classString
	 */
	public function foo(string $classString): bool
	{
		return is_subclass_of(DateTimeInterface::class, $classString);
	}
}
```
@romm romm force-pushed the is-subclass-of-class-string branch from e417b79 to f39ebd3 Compare December 16, 2020 16:06
@ondrejmirtes ondrejmirtes force-pushed the master branch 2 times, most recently from efd31ce to 0471f87 Compare July 29, 2021 14:08
@staabm
Copy link
Contributor

staabm commented Sep 1, 2021

both mentioned cases of the PR description seem to be fixed

https://phpstan.org/r/f10c4833-22f6-4836-a2df-d6fd9cd822b1
https://phpstan.org/r/f97e613a-d4e9-49ff-b92a-3220717702e2

I guess this can be closed.

@romm could you confirm?

@staabm
Copy link
Contributor

staabm commented Sep 1, 2021

looking at the example in phpstan/phpstan#2755 which this PR is trying to fix, it seems there is still a issue though..?

@enumag
Copy link
Contributor

enumag commented Sep 1, 2021

Yeah, my original issue isn't fixed yet. I'm not sure if this PR would fix it though since that case isn't in the tests.

@ondrejmirtes
Copy link
Member

/cc @staabm Could we achieve this the same way as with is_a in #1311 ?

@staabm
Copy link
Contributor

staabm commented May 16, 2022

@ondrejmirtes I fixed the origin problem with #1321

this PR here as is does no longer fix a real issue and can be closed IMO

@ondrejmirtes
Copy link
Member

Okay :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

False-positive with is_subclass_of

4 participants