5 ms·
Is there any way to test php code the same way a compile phase does in other languages to catch obvious mistakes from hitting your users?
by argd678 8y ago
Is there any way to test php code the same way a compile phase does in other languages to catch obvious mistakes from hitting your users?
- pram 8y agoPHP 7 has type hints and a strict mode. Probably as close as you're going to get. It prevents execution from the interpreter.
- n1c 8y agoPHP Static Analysis Tool (https://github.com/phpstan/phpstan https://github.com/phpstan/phpstan) is pretty good at surfacing that kind of thing.
- bunnybender 8y agoPhan (https://github.com/phan/phan https://github.com/phan/phan) is another one. Other potentially useful tools: - PHP_CodeSniffer (https://github.com/squizlabs/PHP_CodeSniffer https://github.com/squizlabs/PHP_CodeSniffer) - GrumPHP (https://github.com/phpro/grumphp https://github.com/phpro/grumphp) - PHP Mess Detector (https://phpmd.org/ https://phpmd.org/)
- DCoder 8y agoThere's also Vimeo's Psalm [0]. [0]: https://github.com/vimeo/psalm https://github.com/vimeo/psalm
- lukifer 8y agoIt's obviously not as comprehensive as compiled or strictly-typed languages, but you can use "php -l" as a linter to catch obvious parsing/syntax bugs. I use this script to check our whole codebase before deployment: > find . -name "*.php" -print0 | xargs -0 -n1 -P8 php -l | grep -v "No syntax errors detected"
- deleted 8y ago[deleted]