phpspec / prophecy

Highly opinionated mocking framework for PHP 5.3+
MIT License
8.53k stars 241 forks source link

Handle "self" type hint #485

Closed greg0ire closed 4 years ago

greg0ire commented 4 years ago

Using self in the implementing class means narrowing the type, and result in an LSP violation (and a rightful crash from PHP). Resolving self to the declaring type results in a compatible signature.

Fixes #484

ciaranmcnulty commented 4 years ago

Wait what, getType() returns self rather than the actual type? FFS PHP

This seems ok to me - it could also have been done in a ClassPatch but they're not really meant for generic issues like this I suppose

ciaranmcnulty commented 4 years ago

Thanks @greg0ire

GrahamCampbell commented 4 years ago

Wait what, getType() returns self rather than the actual type? FFS PHP

Yep, this is by design, and is the same reason it cannot raise a reflection exception. getType is a purely syntactic operation. It just reads the type as is from the parser.

stof commented 4 years ago

We need to do the same for parent

GrahamCampbell commented 4 years ago

~parent is not a valid type?~ Oh: https://3v4l.org/N6OId. 😆