laminas / laminas-stdlib

SPL extensions, array utilities, error handlers, and more
https://docs.laminas.dev/laminas-stdlib/
BSD 3-Clause "New" or "Revised" License
190 stars 40 forks source link

Dropping `@psalm-self-out` to avoid incorrect type inference in inheritance #78

Closed Ocramius closed 1 year ago

Ocramius commented 1 year ago

Before this change, in following example, @psalm-self-out would delete inheritance type information at runtime. For example:

class Foo implements ParentType {
    // ...
}

$foo = new Foo();

$foo->methodWithSelfOut();

/** @psalm-trace $foo */ // produces `ParentType`

This change corrects that, preserving static in the type information.

Q A
Documentation yes
Bugfix yes
BC Break no
New Feature no
RFC no
QA no
Ocramius commented 1 year ago

Note: I noticed the problem while working on laminas-session, which (ab-)uses a lot of the ArrayObject stuff that keeps haunting us everywhere.

internalsystemerror commented 1 year ago

Is it not possible to do @psalm-self-out static<...> to get around this issue?

Ocramius commented 1 year ago

The &static approach is something I had already tried, but caused even more issues.

I will keep using psalm-self-out outside the context of inheritance, in builders and similar abstractions, but it is not a.good fit here 😁