VS Code shows me errors due to local PHP version - php

I am currently working on a PHP Laravel project. For this project I need at least PHP 8.1, so I have a PHP Docker instance. On my Mac I have php 7.3.24. The project runs as expected. But my IDE (VS Code) gives me an error message in many places due to the local PHP version. For example, the typehint of class variables.
In addition, included libraries are not recognised when I want to initiate them (undefined type).
My question: Do I have to upgrade the local PHP version or is there a setting in the IDE?

Related

How to set VS Code extension Intelephense for PHP 8?

I would like to set my bought Visual Studio Code extension to use PHP 8 version for it's "intelisense" functionality.
Checking defaultSettings.json for 'intelephense' search query gives lots of hits, but only one stands out to me for upgrading to PHP 8:
// A semver compatible string that represents the target PHP version. Used for providing version appropriate suggestions and diagnostics. PHP 5.3.0 and greater supported.
"intelephense.environment.phpVersion": "7.4.0",
This should probably be changed in Workspace Settings .vscode\settings.json to
"intelephense.environment.phpVersion": "8.1.0-dev", // or would "8.0.0" be better?
Is there anything else that needs to be changed?
I am using Laragon for local development with PHP 7.2 and 8.0 installed. Staging and production servers use PHP 8.0.

Docker PHP 5.2.17 lint doesn't detect anonymous function

So, I am trying to set up several kinds of tests for several kinds of projects.
One project is still running on PHP 5.2.17 (yeah I know :( ).
So I have been searching the Docker Hub for PHP 5.2.17 images, which is de PHP version running on the production machine.
On the production machine we recently encountered a fatal error on a PHP file in which we used an anonymous function - a feature that has been added to PHP as of version 5.3.
A simple lint on that machine detects that:
php -l corrupt_file.php
The above will show an error like "unable to parse PHP file".
However, I have tried out several PHP 5.2.17 docker images, and executing the same lint in them results in "No errors detected".
I am completely lost. Are those PHP 5.2.17's another more recent version of PHP instead??
I just found out what the problem is:
All the docker images have SHORT_OPEN_TAGS set to "off" in the php.ini.
In that case the PHP linter simply "doesn't see any parse errors" because it doesn't see any PHP.

Change PHP Language Library in eclipse Oxygen

Eclipse for PHP Developers
Version: Oxygen Release (4.7.0)
Build id: 20170620-1800
How can I change the PHP Language Library to PHP 7 (see screen below)? The project results from a previous eclipse version which has been imported to Oxygen. On my machine no PHP is installed, I use Xdebug with a Linux VM, the workspace is on a samba share on that VM (runs PHP 7.0 on Apache).
In the preferences I can add PHP paths, but I have no access to the PHP directory on the Linux VM. But when I create a new PHP project in eclipse, I can select a PHP version (including 7.0).
I wonder if it is the only chance to create a new PHP 7.0 project and copy my files over, or is there a way to alter the PHP 5.6 to PHP 7.0?
Edit: based on howlger's answer
Yes, PHP validation solves it.
I was looking under Validation where is no such thing
Right-click on the project folder and choose Properties
In the properties dialog, in PHP > Validation
Enable project specific settings
As PHP Version choose
7.0 (uniform variable syntax, scalar type hint,...) or
7.1 (void return types, class constant visibility,...)
You also might configure installed PHPs: Window > Properties: PHP > Installed PHPs
See also PHP help: PHP Interpreter Properties

PHP version: module version is higher than installed PHP version

I am using eclipse oxygen for php developers, trying to run php project with version 5.6.
Installed php version: 5.6
PHP version in project facets: 5.6
I tried to follow the the below tutorial, however I could not find php -> interpreter in neither project level nor workspace level.
https://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.wst.server.ui.doc.user%2Ftopics%2Ftwinstprf.html
How to resolve module(project?) version complaint?
I run in the same problem when I tried to run/debug a PHP project via Run As -> Run On Server.
Since you have not developed in detail your case I will try to present my case such that you might understand what might cause the problem and how to fix it.
So what I did was to choose the Run -> Run As -> Run on Server menu when a wizard-like dialog box was shown. I choose the PHP's Built-in Server, specified a PHP installed executable (like 5.6) then in the next screen ("Modify the resources that are configured on the server") by trying to move my project from the "Available" list to the "Configured" list I've got a notice error like the one you mentioned in the title. In my case the project was configured with PHP 7.1 while the PHP executable chosen in the "Run on Server" dialog box was 5.6, thus the conflict.
So the problem is that your project is defined to be validated by one PHP version while you are trying to run/debug it with another PHP version. What you can do to fix this is one of the following:
either choose a PHP executable for your "Run on Server" session that is compatible with the project's PHP version; this can be done easy right in the "Run on Server" screen .
either configure your PHP project to be validate by the same PHP version as the one you are trying to run/debug your project with; this can be done by right-click the project -> Properties -> PHP -> Validation then choosing the right PHP version
I hope it helps.

Set PHP version in Netbeans 7 for non-project files

I'm editing a PHP file in Netbeans that is not part of a project. Although I have PHP 5.3 installed, Netbeans complains about my use of a lambda function: "Language feature not compatible with PHP version indicated in project settings".
Is there a way to tell Netbeans to think in 5.3 when I don't have project settings to edit?
I'm using Netbeans 7.0 with PHP 5.3.3 on Ubuntu.
UPDATE: The code is working, it's just the inspection that is borken.
Right click your project in the Projects tab, click Properties, then on the Sources tab, set the PHP Version. I'm using Netbeans 7.1.2
Go to File Menu of net beans and select project properties of the project and change the version of php from # PHP Version : PHP 5.6 or another.
This Error Showing for PHP version(language feature not compatible with php version indicated in project settings)
I recently did an update to my NetBeans (v7.0.1). I just tried creating a lambda fn and the IDE didn't show any warnings/errors. Try updating your NB.

Categories