Hacker News new | ask | show | jobs
by jspaetzel 1672 days ago
The language type system doesn't quite support that yet in all scenarios. As of php 7/8 it's getting there but for what you are describing you'd need to use a static analysis tool still unfortunately.

Here's two of the most common ones. These are very mature and are very broadly used. Most editors also come with some support for these annotations so you often get help in the editor when something is wrong.

https://psalm.dev/docs/annotating_code/supported_annotations...

https://phpstan.org/writing-php-code/phpdoc-types