Unclear on the difference of using a different PHP version in Language Level and CLI Interpreter

Our project was built in PHP 5.6, but I'm unable to get that version running on my "new" Mac Catalina (it came pre-installed and configured with it) ... and because PHP 5.6 needs a bunch of security downgrades to get it to run on a fresh Catalina install, I got our project working on PHP 7.3 (there was a particular issue with 7.4 that took too long to try to figure out).

Now, I'd like PHPStorm to run suggestions and validations with PHP 5.6 so that my changes won't break stuff on our staging (QA) and production (Prod) servers (as in, inadvertently committing PHP 7+ changes that won't work on 5.6, because I don't have all of the breaking differences memorized all of the time)... 

So, in PHPStorm (macOS) > Preferences > Languages & Frameworks > PHP, I set "PHP language level" to 5.6, but then for "CLI Interpreter" I selected PHP 7.3 because that's what's installed and working... I don't know however if I should even have selected that (as opposed to leaving it empty), or if that could introduce problems with my usage of PHPStorm in the project or allow me to easily accidentally commit breaking changes.

I tried reading JetBrains documentation on this and am left a little confused due to the terminology etc, so I'm not sure what I'm looking at here.

https://www.jetbrains.com/help/phpstorm/php.html

PS the Symfony version is 3.4, though I don't know if that matters here.

0

The PHP version gotten from the interpreter does not matter much in terms of the capabilities. All analysis is performed according to the Language Level: https://www.jetbrains.com/help/phpstorm/supported-php-versions.html

0

> The PHP version gotten from the interpreter does not matter much in terms of the capabilities. 

I'm not sure what you're saying here.

As far as I understand now, PHP Language Level is used for code validation, so that if the repo is PHP 5.6 and I add a function call for something that's only in PHP 7, even though my installed version is 7.3, the editor should show an error in the file (like a red squiggly underline) that will indicate to me that it won't work on a server running PHP 5.

> All analysis is performed according to the Language Level

I'm supposing by "analysis" you're referring to the validation that shows me errors in the file's code. Sorry if I sound nitpicky, it's just easy to garner a different understanding based on subjective terminology.

> https://www.jetbrains.com/help/phpstorm/supported-php-versions.html

The link's content seems to mix up Language Level, interpreter, and installed PHP version, when you're saying the interpreter doesn't matter much in regards to Language Level...

"No correlation between the PHP version used in the project and the language level is enforced."

I can't tell if by "the PHP version used in the project" they mean "what the user selected in the PHPStorm project for Language Level or Interpreter" or "the PHP version the user has installed on the computer that will run the app and also runs PHPStorm". It seems like "project" could be ambiguous here.

"Although the language version of each interpreter is detected automatically, you can still tell PhpStorm to provide you with coding assistance that corresponds to a different language level."

This is where it seems to mix Language Level and Interpreter in an equal way, but you're saying the connection is tenuous... so, am I correct that Language Level is just used for file code validation (to warn me if I'm adding code not compatible with the Language Level), and that Interpreter is not used by Language Level to validate, but only for when I run code using PHPStorm? 

"However, if you attempt to use a code construct that is not supported by the specified language level, PhpStorm suggests a Switch to PHP <version> quick-fix."

This makes sense when I'm only considering Language Level and not Interpreter, but I may have been under a misunderstanding that Language Level uses Interpreter to validate code (and maybe it does, and can do it properly even if Interpreter is at a higher version than Language Level).

1

@Vadiru

PHP Interpreter is used to execute your code (e.g. "PHP Script" type of Run/Debug Configuration), by PhpStorm's built-in simple web server (if you are using it for PHP files), by local PHP-based tools (e.g. for PHPUnit tests, CodeSniffer etc), Phing (a built tool/task runner; similar to Ant)

PHP Interpreter is NOT needed for just wring the code and not using any extra tools for that (like PHP CS Fixer).

Language Level is what is used for static analysis/validating your code (what PHP features are available; function signatures, class/function/const availability).

-----

You can write your PHP code without having any PHP installed (hence no PHP Interpreter at all).

This also means that you can select Language Level to be latest PHP 8.0 and have PHP Interpreter to be 5.3. You will not be able to execute your code (the execution will fail if 5.4+ feature will be used for obvious reasons) but you can still write your PHP code.

 

so, am I correct that Language Level is just used for file code validation (to warn me if I'm adding code not compatible with the Language Level), and that Interpreter is not used by Language Level to validate, but only for when I run code using PHPStorm? 

Yes.

but I may have been under a misunderstanding that Language Level uses Interpreter to validate code (and maybe it does, and can do it properly even if Interpreter is at a higher version than Language Level).

No. All validation (syntax checks etc) is done in Java/Kotlin. The IDE does not use the actual PHP to lint your code.

1

请先登录再写评论。