Skip to content

Why is the order of method calls important here? #4712

Answered by Kocal
AnjaLiebermann asked this question in Support
Discussion options

You must be logged in to vote

Hi,

setCreatedOn() is a method from History and its return type is self. So even if you create a new class that extends History and call setCreatedOn, your typing tells PHPStan/PHP it will returns History instance but not ProfessionalActivityText.

Your second example is neither ok, $professionalActivity is also seen as History instance:

To get it working, you must change self to static, by using PHPDoc or use PHP 8.

This is a correct version of your code: https://phpstan.org/r/466b3f71-0a74-4fe1-a9ae-b4c1c436990b

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@AnjaLiebermann
Comment options

Answer selected by AnjaLiebermann
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Support
Labels
None yet
2 participants