I am getting this error:
PS C:UsersUserDesktopjk> php artisan serve
PHP Fatal error: Uncaught ErrorException: Method ReflectionParameter::getClass() is deprecated in C:UsersUserDesktopjkvendorlaravelframeworksrcIlluminateContainerContainer.php:788
Stack trace:
Composer.json
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": "^7.4|^8.0",
"laravel/framework": "5.4.*",
"laravelcollective/html": "^5.3.0",
"guzzlehttp/guzzle": "^6.3",
"doctrine/dbal": "^2.9"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "^9.3",
"symfony/css-selector": "3.1.*",
"symfony/dom-crawler": "3.1.*"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\": "app/"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
},
"scripts": {
"post-root-package-install": [
"php -r "file_exists('.env') || copy('.env.example', '.env');""
],
"post-create-project-cmd": [
"php artisan key:generate"
],
"post-install-cmd": [
"Illuminate\Foundation\ComposerScripts::postInstall",
"php artisan optimize"
],
"post-update-cmd": [
"Illuminate\Foundation\ComposerScripts::postUpdate",
"php artisan optimize"
]
},
"config": {
"preferred-install": "dist",
"platform": {
"php": "8.0.1"
}
}
}
Container.php Here some part of code
protected function resolveClass(ReflectionParameter $parameter)
{
try {
return $this->make($parameter->getClass()->name);
}
// If we can not resolve the class instance, we will check to see if the value
// is optional, and if it is we will return the optional parameter value as
// the value of the dependency, similarly to how we do this with scalars.
catch (BindingResolutionException $e) {
if ($parameter->isOptional()) {
return $parameter->getDefaultValue();
}
throw $e;
}
}
Method ReflectionParameter::getClass() is deprecated .i think is getclass method is deprecated in version 8.0.1nstead of this i trying to using ReflectionParameter::getType()like link but not working .and also members suggest this
Laravel app stopped working after upgrading to php 8 i tried this also but not working
4
Answers
You can replace it with
getType()
, which the documentation suggest. You have to create your ownReflectionClass
, from theReflectionType
. This should do the trick.I have this sandbox, that helped me assure it was working as intended.
Laravel 5.4 seems to have incorrect platform requirements. Specifically that it requires PHP version >= 5.6 however it has code that will not work in PHP 8. Since 5.4 is end of life I would not expect any official code changes to make it work for PHP 8 so you would either need to fork and maintain your own Laravel 5.4 branch that solves these problems or upgrade your Laravel version to one that supports PHP 8.
The first Laravel version that supports PHP 8 is Laravel 6
because ReflectionParameter::getClass() is deprecated in php 8 .
solution go to
and go to
protected function resolvePrimitive(ReflectionParameter $parameter)
and replace
$parameter->getClass()** with **$parameter->getType()->getName()
.You might need to update your global composer.json with:
I had some annoying issue so I hade to run: