Search code examples
phphhvm

PHP - static type checking a-la PhpStorm


I am a strongly-typed language supporter but I am working on a big PHP project.

I have been using PhpStorm and I love the extra type hinting you can provide, with comments like these:

/** @var \Payments $payment */

/** @property \Payments $payment */

PhpStorm is great because it gives you some warning when types don't match.

I was wondering if it is possible to have this kind of check also statically, outside of PhpStorm. Some kind of command line precompiler that would go through the code, checking also those extra hints, to show some error if a mismatch is detected.

Is that something that can be done with phpcs?

My ultimate goal is to have an automated tool that will alert me for type mismatches.

I was even considering switching to HHVM to have far better type hinting. But I don't trust HHVM yet to run on production.

Ideally it would be great to develop on HHVM for the extra type hinting but the code wouldn't run on the Zend PHP engine that I want to keep on production.

Any idea?

Thanks.


Solution

  • For static code analysis, specifically helping with type error detection, one can use tools like

    PHPCS aka PHP_CodeSniffer is Coding Standard checker, not really helpful with type error detection.