The best way to get the full PHP version string

Jeff Geerling shares the best way to get the full PHP version string.  I’d think that “php –version” externally or “echo PHP_VERSION” internally would do the job.  However, that’s not exactly right, as there are a number of inconsistencies on different platforms.  The best option seems to be the combination of the PHP_MAJOR_VERSION, PHP_MINOR_VERSION, and PHP_RELEASE_VERSION constants.

$ php -r 'echo join(".",[PHP_MAJOR_VERSION,PHP_MINOR_VERSION,PHP_RELEASE_VERSION]);'
7.2.12

Leave a Comment