Getting an PHP Deprecated error : ReflectionParameter::getClass() [duplicate] - php

after updating my mac to php 8 laravel app stopped working, this is the error I'm getting:
Deprecated: Method ReflectionParameter::getClass() is deprecated in /Users/.../Sites/.../vendor/laravel/framework/src/Illuminate/Container/Container.php on line 871
Deprecated: Method ReflectionParameter::getClass() is deprecated in /Users/.../Sites/.../vendor/laravel/framework/src/Illuminate/Container/Container.php on line 945
Deprecated: Method ReflectionParameter::getClass() is deprecated in /Users/.../Sites/.../vendor/laravel/framework/src/Illuminate/Container/Container.php on line 871
Deprecated: Method ReflectionParameter::getClass() is deprecated in /Users/.../Sites/.../vendor/laravel/framework/src/Illuminate/Container/Container.php on line 945
I've tried to fix the issue by investigating the code with no luck

THE SOLUTION
As explained here latest version of laravel 6, 7 and 8 has made changes required for php 8. all you have to do is:
1- add php 8 to your composer.json (I've kept v7.4 just in case production server does not support php 8 yet)
"php": "^7.4|^8.0",
2- to run composer update to update your laravel to the latest version
composer update
3- make sure update the following libraries since they exist in all laravel applications
PHP to php:^8.0
Faker to fakerphp/faker:^1.9.1
PHPUnit to phpunit/phpunit:^9.3
4- check for any other library which needs to be updated, contribute if they haven't supported php 8. but you should be good to go with most of the libraries since they have active contributors.
EXPLAINING THE PROBLEM
as described here
PHP 8 introduces several improvements in PHP type systems such as the introduction of Union Types, mixed type, and a few more.
With these changes, certain methods in Reflection API's
ReflectionParameter yield incorrect results.
In PHP 8, the following methods from ReflectionParameter class is
deprecated:
ReflectionParameter::getClass()
ReflectionParameter::isArray()
ReflectionParameter::isCallable()
ReflectionParamter::getType() is the recommended way to replace the
deprecated methods. This method is available in PHP 7.0 and later.

Check your php version in your virtual machine(xampp or server).
php --version
Is that version PHP 8 ? Am I right? That's the cause of the problem:
PHP 8 introduces several improvements in PHP type systems such as the introduction of Union Types, mixed type, and a few more.
With these changes, certain methods in Reflection API's ReflectionParameter yield incorrect results.
In PHP 8, the following methods from ReflectionParameter class is deprecated:
ReflectionParameter::getClass()
ReflectionParameter::isArray()
ReflectionParameter::isCallable()
ReflectionParamter::getType()
Downgrade your php version to 7.4 and your Laravel app works like a charm!

I had similar issue. But I had already run brew update and brew cleanup before I noticed the issue. What I did:
I noticed this error from brew cleanup:
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink bin/node
Target /usr/local/bin/node
already exists. You may want to remove it:
rm '/usr/local/bin/node'
To force the link and overwrite all conflicting files:
brew link --overwrite heroku-node
I ran the commands:
brew link --overwrite composer
composer upgrade
composer update
That's what worked for me

If you're using valet you should do the followings:
Downgrade from php8+ to php7.4 valet isolate php#7.4
Then run composer update using valet valet composer update

Related

Upgrading php to 8

Both my valet and composer is using php 8.0
But my local says
Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.0.2". You are running 7.4.30. in /Users/admin/sites/sage10/web/app/themes/sage10/vendor/composer/platform_check.php on line 24
When I upgrade php with valet using 8.0 it gives
Deprecated: Method ReflectionParameter::getClass() is deprecated in /Users/admin/.composer/vendor/illuminate/container/Container.php
But at the end it says its using 8.0. and composer -vvv about also gives php 8.0
Is there more things to consider? I don't understand why its saying I'm using 7.4...
Composer works on the php version is in use on command line. It is possible you have multiple version installed.
Try to run
php -v
Then ensure composer is updated to the latest version (2.4.2)
composer -V
In case update it
composer self-update
If self-update gives you some runtime error, reinstall composer following the install procedure
Then the error you get is about Laravel 6/7/8 version with PHP 8, the solution is here
Laravel app stopped working after upgrading to php 8
I had a line of required package that was not needed and supported with sage 10// php8 (illuminate/support) inside my global composer file. After erasing that and linking my valet with php database and restarting it, everything started to work.

Fatal error: Uncaught Error: Class "Phalcon\Config" not found in Phalcon Php application

I installed Phalcon PHP version 5.0.0beta3 in my Ubuntu, because it's compatible with PHP 8.0, but when I run my application some Phalcon classes are not found, I already installed the psr module using the following command:
sudo apt install php8.0-psr
and I have installed phalcon.so by direct download from phalcon php github releases, so when I access my phpinfo() I can see it there:
evidence of phalcon.so instalation
any idea what's going on?
Phalcon 5 has a number of backwards incompatible changes. Most prominent is all the classes in the base Phalcon namespace were moved to more accurate locations.
Phalcon\Config -> Phalcon\Config\Config
Phalcon\Di -> Phalcon\Di\Di
Etc
Check the release notes at https://github.com/phalcon/cphalcon/blob/master/CHANGELOG-5.0.md for specific changes.

PHPUnit can't detect PHP 7.3.2

I’ve successfully installed PHPUnit, but I am running into some problems. When I try to run it on the command line, I get this message:

> “PHPUnit 8.0.4 by Sebastian Bergmann and contributors. This version of
PHPUnit is supported on PHP 7.2 and PHP 7.3. You are using PHP 7.1.23
(/usr/bin/php).”
When I type “php –v” in the command line, the system verifies that I’m using version 7.1.23 of the language.
When I tried to install PHP 7.3.2, Homebrew gives me the following message:
“Warning: php 7.3.2 is already installed, it's just not linked You can
use brew link php to link this version."
When I try to link, it tells me:
"Linking /usr/local/Cellar/php/7.3.2... Error: Could not symlink
sbin/php-fpm /usr/local/sbin is not writable.”
So PHP 7.3.2 does exist on my system, but PHPUnit is not detecting it. Would you happen to know of any fix for this? Is there a way to switch to 7.3.2, or to perhaps install an earlier release of PHPUnit that’s compatible with PHP 7.1.23?
Thanks in advance for any help you can give.
Maybe you should just try with sudo?
sudo brew link php
Edit: It's not a good idea. Please ignore.

Composer Downgrade php version 7.1 to 7.0 on windows

I am working on Laravel project where one of its packages require PHP 7.0 version. Currently, I have installed latest version but now I want to downgrade it to 7.0. How should I do this? Is it possible with command line or do I need to change PHP files manually? I tried to find this topic on google also on StackOverflow but can't find any solution for this problem
I found one solution here but unable to implement that
here is the link I tried
This is the error I get with 7.1 version
Function mcrypt_module_open() is deprecated

mcrypt and PHPUnit

I am using PHPUnit to test a project where mcrypt is heavily used. I have installed phpunit using this SO answer.
Whenever I try and run phpunit, I get the following error:
Fatal error: Call to undefined function mcrypt_create_iv() in
/files/file/using/mcrypt/thing.php on line 20
How can I fix this error? Do I have to install mcrpyt especially for PHPUnit?
You can either install MCrypt (which you should do anyway) or mark that specific test as one requiring MCrypt. The latter will cause the test to be skipped if you don't have MCrypt installed.

Categories