I am getting this error:
PS C:\Users\User\Desktop\jk> php artisan serve
PHP Fatal error: Uncaught ErrorException: Method ReflectionParameter::getClass() is deprecated in C:\Users\User\Desktop\jk\vendor\laravel\framework\src\Illuminate\Container\Container.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
because ReflectionParameter::getClass() is deprecated in php 8 .
solution go to
vendor\laravel\framework\src\Illuminate\Container\Container.php
and go to
protected function resolvePrimitive(ReflectionParameter $parameter)
and replace
$parameter->getClass()** with **$parameter->getType()->getName() .
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
You can replace it with getType(), which the documentation suggest. You have to create your own ReflectionClass, from the ReflectionType. This should do the trick.
$reflectionClass = new ReflectionClass($reflectionParam->getType()->getName());
I have this sandbox, that helped me assure it was working as intended.
You might need to update your global composer.json with:
composer global update
I had some annoying issue so I hade to run:
composer global update --ignore-platform-reqs
Related
I build an aplication in Laravel 9 using Laravel Breeze and also vite. There is no problem with my application on my localhost (PHP 8.2). Problem stars when I try to deploy the application on server, I did everything normally according to Laravel Deployment documentation, but I am still getting this error from log on server: PHP Fatal error: Uncaught ErrorException: Method ReflectionParameter::getClass() is deprecated in and after this there is an list of files where this method is used I assume.
I googled this error, but every answer about this problem is only when someone was upgrading older project to PHP 8.0 or higher.
Here is also my composer file and I think I got everything in order:
`{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"php": "^8.0.2",
"guzzlehttp/guzzle": "^7.2",
"laravel/framework": "^9.19",
"laravel/sanctum": "^3.0",
"laravel/tinker": "^2.7",
"livewire/livewire": "^2.10",
"nesbot/carbon": "^2.64"
},
"require-dev": {
"fakerphp/faker": "^1.9.1",
"laravel/breeze": "^1.15",
"laravel/pint": "^1.0",
"laravel/sail": "^1.0.1",
"mockery/mockery": "^1.4.4",
"nunomaduro/collision": "^6.1",
"phpunit/phpunit": "^9.5.10",
"spatie/laravel-ignition": "^1.0"
},
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"#php artisan package:discover --ansi"
],
"post-update-cmd": [
"#php artisan vendor:publish --tag=laravel-assets --ansi --force"
],
"post-root-package-install": [
"#php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"#php artisan key:generate --ansi"
]
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true
}
},
"minimum-stability": "dev",
"prefer-stable": true
}`
Thanks.
I tried everything, including composer update and I double-checked my deployment method, which I am using for every project.
It is usually caused by a compatibility issue between the version of PHP on your server and the version of Laravel and its dependencies that you are using.
The ReflectionParameter::getClass() method has been deprecated in PHP 8.0 and removed in PHP 8.2.
To resolve this issue, you may need to update your application to a version of Laravel that is compatible with PHP 8.2 and its dependencies.
Additionally, you can try downgrading the PHP version on your server to a version that is supported by your application, or upgrading your application to a version that is compatible with the PHP version on your server.
It seems like in your local you are having PHP version less than 8.2 and in your server it is 8.2. You can check it by adding the following code to a route or controller in your Laravel application:
<?php
phpinfo();
Sorry guys, mistake was on my end :). I have two project (old one from 2017 and this new one) on one server. I just set root directory on this new domain to old version of project. :)
I'm trying update a laravel from 5.4 version to 5.5. I have done everything with instruction from laravel guide:
https://laravel.com/docs/master/upgrade
When I'm trying use command:
composer update
the result is:
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- The requested package laravel/framework 5.5.* is satisfiable by laravel/framework[5.5.x-dev] but these conflict with your requirements or minimum-stability.
Below I show composer.json file:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.6.4",
"doctrine/dbal": "^2.5",
"intervention/image": "^2.3",
"laravel/framework": "5.5.*",
"laravel/tinker": "~1.0",
"laravelcollective/html": "^5.4.0",
"unisharp/laravel-filemanager": "^1.7"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~6.0"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"artSite\\": "app/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"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",
"sort-packages": true
}
}
I would be greateful for help. Best regards
as stated in the error message Laravel 5.5 is still in dev, meaning there's no stable release and by default Composer limits you to downloading only stable numbered releases to avoid you downloading any packages that are in active development and may contain breaking changes.
You can circumvent this by adding the following two lines to your composer.json file
"minimum-stability": "dev",
"prefer-stable": true,
This way it prefers stable releases wherever it can find them but it will allow you to download dev packages if nothing else is available.
I think you should update the PHP version as well. If you check the official doc, it says the minimum PHP requirement 7.0.0.
when i run a command in laravel project :
php artisan optimize
[Symfony\Component\Debug\Exception\FatalErrorException]
Call to undefined function get()
Script php artisan optimize handling the post-update-cmd event returned with an error
[RuntimeException]
Error Output:
and
php artisan clear-compiled
[Symfony\Component\Debug\Exception\FatalErrorException]
Call to undefined function get()
and
php artisan optimize --force
[Symfony\Component\Debug\Exception\FatalErrorException]
Call to undefined function get()
and
{
composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Removing barryvdh/laravel-ide-helper (v2.1.4)
- Removing symfony/class-loader (v3.1.0)
Writing lock file
Generating autoload files
Illuminate\Foundation\ComposerScripts::postUpdate
php artisan optimize
[Symfony\Component\Debug\Exception\FatalErrorException]
Call to undefined function get()
Script php artisan optimize handling the post-update-cmd event returned with an error
[RuntimeException]
Error Output:
}
and my composer.json is
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.2.*",
"laravelcollective/html": "5.2.*"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~4.0",
"symfony/css-selector": "2.8.*|3.0.*",
"symfony/dom-crawler": "2.8.*|3.0.*"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
},
"scripts": {
"post-root-package-install": [
"php -r \"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"
}
}
so, what's wrong is it,and how can i fix it? thanks?
This error also comes when you did an error in creating a route.
Instead of Route::get(...) you may have put Route:get(...), So just check in your route or Controllers files
You're using get() method in a wrong way somewhere in your app (model or controller). Fix it and all commands will work again.
If you want more help, please post your recently added code which uses get() method.
I'm worrying about Laravel and long term support concepts, related to my application.
Now I've developed my app on lrvl 5.2, but the LTS version is the 5.1.
Since I'd like to have a long term supported framework as my application basement, I wonder if it's the case to downgrade to 5.1. No features problems should arise for my specific app. But this is another story... not the topic of this question.
Secondly I don't see how to tell composer to stick to laravel 5.1 then,
i.e. when I'll run a composer update avoid updating the laravel 5.1 version.
Should I also worry about tweaking composer from updating the dependency packages?
In your composer.json, find and edit this line:
"laravel/framework": "5.1.*",
That is how you force Composer stick with a specified version.
Hope it helps.
For more information: https://getcomposer.org/doc/articles/versions.md
composer.json for Laravel 5.1 LTS
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.1.*"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~4.0",
"phpspec/phpspec": "~2.1"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
},
"scripts": {
"post-root-package-install": [
"php -r \"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"
}
}
I am installating plivo api using composer on live server(digital ocean), which running command i getting some dependencies version mismatch errors.
plivo required guzzle latest version, but guzzle is already installed in my laravel application but its version is old.What i need to do to resolve this error.
please help me to resolve those.
here is the composer.json
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"laravel/framework": "5.0.*",
"laracasts/flash": "^1.3",
"fzaninotto/faker": "~1.4",
"barryvdh/laravel-debugbar": "~2.0",
"orchestra/imagine": "~3.0",
"zendframework/zendsearch": "dev-master",
"mmanos/laravel-search": "dev-master",
"dimsav/laravel-translatable": "~5.0",
"twilio/sdk": "*",
"fillup/nexmo": "dev-master",
"guzzlehttp/log-subscriber": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"phpspec/phpspec": "~2.1",
"illuminate/html": "~5.0"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/",
"Lib\\": "lib/"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-update-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-create-project-cmd": [
"php -r \"copy('.env.example', '.env');\"",
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
}}
here is the screen shot
Plivo Sales Engineer here.
You should not use guzzlehttp/log-subscriber (it is depreciated as noted in the comments) but rather use any logger which implements a PSR-3 interface. See this SO post for how to do it with the builtin guzzle middleware and monolog or there is also the guzzle-log-middleware.
One other note: the latest version of plivo-php is 1.1.0. I'd encourage you to use that. It requires Guzzle v6.1.1.
According to plivo/plivo-php, it requires Guzzle v6.1.
guzzlehttp\log-subscriber is only compatible with Guzzle v4 and v5.
If you are attempting to log the Request or Response you can use GuzzleHttp\Middleware::log