Repository navigation
Replies: 3 comments 2 replies
|
Overriden properties with different types are not sound because they are both readable and writable by parent and child classes. So the parent class wouldn't know it has to assign the extra offsets the child class wants there. This error can be turned off by setting Personally I wouldn't choose to do inheritance here at all, but rather composition with interfaces. Options are implementation detail of a single implementation. If you're trying to store a file and you want different backends, you can pass options to the different backend classes through constructor, they do not need to have a common parent class, only a common interface you will typehint in the rest of the system. |
|
@ondrejmirtes its 3rd party Library, so i can't change much of it: Mage version: and i don't see my problem "resolved" |
|
Stub files are per class, so each of the three classes can have its own shape. What makes the shapes clash is that Declaring those three keys as optional in both shapes makes it work:
Level 10 with bleeding edge, no errors, and With phpstan-strict-rules on (as in your snippet), the two overrides are also reported as "not the same as" the parent type, because a writable property is only sound when its type is unchanged: https://phpstan.org/r/434c356a-0cb2-4274-806a-86443198ca86. That is the error that The playground has no stub files, so the snippet declares the Zend classes inline. In a project, put those two class declarations, with only the |
Uh oh!
There was an error while loading. Please reload this page.
if a class has a property for options:
that should be overwritten by other classes, i can't really define a Array Shape for them.
i could add
|array{...<string, int|bool|string|null>}to the type, and the error disappears,but then i get the warning for
Offset 'xyz' might not exist.Example:
https://phpstan.org/r/b60aa2e5-6776-461a-af3f-c420fab36582
what would be the preferred solution there?
All reactions