PHP "Undefined" errors after installing Laravel in VS Code - php

All I did was create a new Laravel project with composer create-project laravel/laravel games_review and I started getting these errors without touching a single line in the PHP code.
I also see a VS Code error that says
The PHP Language Server server crashed 5 times in the last 3 minutes. The server will not be restarted.
Source: PHP IntelliSense (Extension)
I have PHP in my path and when I type php -v into the console, it says
PHP 8.0.3 (cli) (built: Mar 2 2021 23:34:05) ( ZTS Visual C++ 2019 x64 )
Copyright (c) The PHP Group
Zend Engine v4.0.3, Copyright (c) Zend Technologies
In VSCode, I have three PHP extension packs installed
PHP Intelephense
PHP Debug
PHP IntelliSense
I have nothing related to PHP in my VSCode settings.json file

Related

PHP IntelliSense on Fedora, executable not found

I have Visual Studio Code installed on Fedora V 36. Even though I've set the php executable in the setttings.json file I'm still getting
PHP executable not found. Install PHP 7.4.0 or higher and add it to your PATH or set the php.executablePath setting
settings.json
{
"php.executablePath": "/usr/bin/php",
"php.validate.executablePath": "/usr/bin/php",
}
whereis php shows
php: /usr/bin/php /usr/lib64/php /usr/share/php /usr/share/man/man1/php.1.gz
php -v shows
PHP 8.0.24 (cli) (built: Sep 28 2022 15:32:34) ( NTS gcc x86_64 )
Copyright (c) The PHP Group
Zend Engine v4.0.24, Copyright (c) Zend Technologies
The question is, how can I get VS Code, or rather IntelliSense, to recognize the php executable?
The answer was that VsCode was having a permission issue with the php executable, due to VsCode being installed from Flatpak.
After some trial and error I ended up uninstalling the Flatpak version of VsCode and re-installing with directions from the official site.
https://code.visualstudio.com/docs/setup/linux#_rhel-fedora-and-centos-based-distributions

After 'composer install', composer says the php version is different. How do I solve it?

I've tried several attempts and the results are all unsuccessful.
composer says my php version is 7.3 but i am already installing php 8.0.2
I've seen some posts in the same situation as me, but it didn't solve anything at all.
this is my test server error code
Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.0.2". You are running 7.4.23. in /home/vagrant/code/interproindigo/vendor/composer/platform_check.php on line 24
But when I run php -v, the php version is 8.0.9 as follows
PHP 8.0.9 (cli) (built: Jul 30 2021 13:03:39) ( NTS ) Copyright (c) The PHP Group Zend Engine v4.0.9, Copyright (c) Zend Technologies with Zend OPcache v8.0.9, Copyright (c), by Zend Technologies
How can I solve this problem?
The problem occurred because the php version of the real server and the test server did not match.
php7.4 -f /usr/local/bin/composer update
Entering this code solved the problem.

Symfony only detects lowest php version

I installed Wamp64, comes with 3 versions of php 5.6, 7.0 and 7.1
When I try to create a new symphony project I receive this error:
Could not find package symfony/skeleton with stability stable in a version > installable using your PHP version 5.6.31.
Obviously I need to activate php7 which I did, I restarted wamp services(apache ...etc) and I still get the same error. Please see attached image
Your PHP path probably points to the bad PHP version.
Try to type
php -v
If the version is not good you can change it by changing your path by typing, environment variable in your Windows search bar.
After that edit the value of the var Path and add the PHP bin folder
For me :
C:\PHP\bin\
And that's all
(Try to learn docker or install your development environment manually and use PHP built-in server to run your project, wamp is good when you start but you don't know how all work and this is bad :( )
i have same issue :
php --version
PHP 7.3.9 (cli) (built: Feb 17 2020 12:46:14) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.9, Copyright (c) 1998-2018 Zend Technologies
But symfony always output :
Could not find package symfony/website-skeleton with stability stable in a
version installable using your PHP version 5.6.30.

error upgrading php in mac

I am running OSX El Capitan (version 10.11.6).
I had php 5.5 installed.
Phpunit requires php5.6 and more so I tried to upgrade my php to 5.6. I couldn't do it so I gave php7 a try.
I followed these guides:
https://coolestguidesontheplanet.com/upgrade-php-on-osx/
https://php-osx.liip.ch/
Mac upgraded PHP to 5.6, but CLI php -v get 5.3.28?
My current output with php -v is :
PHP 7.0.12 (cli) (built: Nov 1 2016 10:21:11) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.12, Copyright (c) 1999-2016, by Zend Technologies
with Xdebug v2.4.1, Copyright (c) 2002-2016, by Derick Rethans
Funny thing, my output with a phpinfo(); when called from somewhere inside a Symfony project, is still PHP Version 5.5.36
Any ideas??
Terminal uses a different PHP than a HTTP server in browser. You can check what PHP you're using in CLI (command line interface) by this terminal command:
$ which php
I don't know if you use any AMP stack (like MAMP). They include their own PHP, so you need to update them in order to have a different PHP version in browser.
Maybe you can use this trick to determine what PHP versions you use in browser / CLI: Find the php.ini path in your phpinfo() output and compare it with this terminal command:
$ php -i | grep php.ini
It's always a good idea to use the debug URL to troubleshoot your Symfony projects; to use this, simply append:
app_dev.php
For example if your route was like http://myhome/, then you would use:
http://myhome/app_dev.php
Then on the bottom of your browser you will have the Symfony debug bar. In the bottom right corner, the version of Symofny is shown, an if you move your mouse over it, you will see the version of PHP; plus also a link to "View phpinfo()". You can click on it to view the full PHP information, including where the PHP file is located.
The PHP config file used (shown on the phpinfo() page) is shown by:
Loaded Configuration File
Hope that helps!

sqlsrv running on php 5.4

I've just upgraded from PHP 5.3.10 to 5.4, now I get the following when trying to initialise php on the command line in windows:
C:\php5.4>php -v
PHP Warning: PHP Startup: sqlsrv: Unable to initialize module
Module compiled with module API=20090626
PHP compiled with module API=20100525
These options need to match
in Unknown on line 0
PHP 5.4.0 (cli) (built: Feb 29 2012 19:06:50)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
This should be a straight swap. I've downloaded the NTS version of php (same as 5.3.10 version) & referenced the php_sqlsrv_53_nts_vc9.dll (v2) of sqlsrv.
Out of interest I also have the sqlsrv v3.0 extension, which I tried to load in and get the same error.
Has anyone else had this issue, or know of how to fix it?
TIA
D
It looks like the version of the dll you have is for PHP 5.3
I'm not sure if there is a version out for 5.4 yet, but you can check the PHP Extensions for Windows page to see.
The system requirements page from Microsoft appears to indicate not (although it may not have been updated yet).
Only you need this link: https://www.microsoft.com/en-us/download/details.aspx?id=20098 the version 3.0
Regards

Categories