Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the format for PHPStan's "phpVersion" config option?

Tags:

php

phpstan

I've been searching and reading and hunting and pulling my hair. This is the only mention of phpVersion: https://phpstan.org/config-reference#phpversion

If you want to analyse a codebase as if it was written for a different PHP version than you’re currently running, change the phpVersion parameter:

parameters:
    phpVersion: 70400 # PHP 7.4

What the...? "70400"? Why this weird format? Does that mean that PHP 8.1 is supposed to be written as "80100"? This really confuses me. I've never see this format before, and it's not mentioned with one single word.

Also, I have to put this into the .neon config? I cannot specify it on the command line? That really further complicates things needlessly.

like image 580
user17535142 Avatar asked Sep 20 '25 00:09

user17535142


1 Answers

It’s the same format the PHP_VERSION_ID constant uses.

So you can just type php -r "echo PHP_VERSION_ID . PHP_EOL;" to get it.

If you want to emulate another version, you can do:

$otherVersion = "8.0.0";
$version = explode('.', $otherVersion);

echo $version[0] * 10000 + $version[1] * 100 + $version[2];
# would print 80000
like image 193
Ondřej Mirtes Avatar answered Sep 23 '25 06:09

Ondřej Mirtes