Re:PHP is worth learning and using
by monkey_monkey on Thursday November 18, 2021 @07:23AM
(#29264617)
> In my opinion, a worse problem with PHP is that classes properties are dynamic.
There's a current RFC that is aiming to deprecate this 'feature'.
You can also add annotations like `/* @var []int */`. External tools (psalm, phpstan) use annotations in their static analysis of the code and will raise an error if $x elements are not integers.
Of course, it's far from Haskell, but my experience with types in PHP is smoother than in Python. Though it was 2 years ago in Python, and the environnement has probably matured.
In my opinion, a worse problem with PHP is that classes properties are dynamic. `class A {}; $a=new A; $a->x=1;` is perfectly valid and will add a property to the object that does not exist in the class. There's no simple way to forbid this, even at runtime (hacking the magic `__set()` creates other pain points).