Why is the order of method calls important here? #4712
-
This throws an error: while this is perfectly ok: Difference is the order of the called methods in the last lines. Why, oh why? This error drove me nuts for weeks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi,
Your second example is neither ok, To get it working, you must change This is a correct version of your code: https://phpstan.org/r/466b3f71-0a74-4fe1-a9ae-b4c1c436990b |
Beta Was this translation helpful? Give feedback.
Hi,
setCreatedOn()
is a method fromHistory
and its return type isself
. So even if you create a new class that extendsHistory
and callsetCreatedOn
, your typing tells PHPStan/PHP it will returnsHistory
instance but notProfessionalActivityText
.Your second example is neither ok,
$professionalActivity
is also seen asHistory
instance:To get it working, you must change
self
tostatic
, by using PHPDoc or use PHP 8.This is a correct version of your code: https://phpstan.org/r/466b3f71-0a74-4fe1-a9ae-b4c1c436990b