PHP Deprecation in PHP 8

Hi,

We are using sage custom theme in our WP project.
Recently i have updated WordPress to the latest version and PHP from 7.4 to 8.2.
After the update, i am seeing lots of error in my theme/vendor/ folder files.

Some of the errors are:
[11-Jan-2024 11:11:35 UTC] PHP Deprecated: Return type of Illuminate\Support\Collection::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /code/wp-content/themes/theme-name/vendor/illuminate/support/Collection.php on line 1789
[11-Jan-2024 11:11:35 UTC] PHP Deprecated: Return type of Illuminate\Support\Collection::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /code/wp-content/themes/theme-name/vendor/illuminate/support/Collection.php on line 1800
[11-Jan-2024 11:11:35 UTC] PHP Deprecated: Return type of Illuminate\Support\Collection::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /code/wp-content/themes/theme-name/vendor/illuminate/support/Collection.php on line 1768
[11-Jan-2024 11:11:35 UTC] PHP Deprecated: Return type of Illuminate\Support\Collection::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /code/wp-content/themes/theme-name/vendor/illuminate/support/Collection.php on line 1747
[11-Jan-2024 11:11:35 UTC] PHP Deprecated: Return type of Illuminate\Support\Collection::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /code/wp-content/themes/theme-name/vendor/illuminate/support/Collection.php on line 1716

Here is screenshot of composer.json file -Screenshot by Lightshot

Should i need to update composer file with PHP 8.2 version or update theme ?
How to update ? Please provide a solution…
Thanks.

Assuming this is a Sage 9 theme, see Sage 9 + PHP 8.0

Hi,
Yes it is Sage 9.
Here is the existing composer.json file code:
{
“name”: “roots/sage”,
“type”: “wordpress-theme”,
“license”: “MIT”,
“description”: “WordPress starter theme with a modern development workflow”,
“homepage”: “Sage | WordPress Starter Theme with Tailwind CSS & Blade | Roots”,
“authors”: [
{
“name”: “Ben Word”,
“email”: “ben@benword.com”,
“homepage”: “https://github.com/retlehs”
},
{
“name”: “Scott Walkinshaw”,
“email”: “scott.walkinshaw@gmail.com”,
“homepage”: “https://github.com/swalkinshaw”
},
{
“name”: “QWp6t”,
“email”: “hi@qwp6t.me”,
“homepage”: “https://github.com/qwp6t”
}
],
“keywords”: [“wordpress”],
“support”: {
“issues”: “https://github.com/roots/sage/issues”,
“forum”: “https://discourse.roots.io/”
},
“autoload”: {
“psr-4”: {
“App\”: “app/”,
“Api\”: “api/”
}
},
“require”: {
“php”: “>=7.1”,
“composer/installers”: “~1.0”,
“illuminate/support”: “5.6.*”,
“roots/sage-lib”: “~9.0.9”,
“soberwp/controller”: “~2.1.0”,
“roots/sage-woocommerce”: “^1.0”
},
“require-dev”: {
“squizlabs/php_codesniffer”: “^2.8.0”,
“roots/sage-installer”: “~1.6”
},
“scripts”: {
“test”: [“phpcs”],
“post-create-project-cmd”: [
“Roots\Sage\Installer\ComposerScript::postCreateProject”
]
}
}

Queries:

  1. Should I replace the full code below (that you shared in https://discourse.roots.io/t/sage-9-php-8-0/22485/15 ) ?
  2. What about the PHP version line “php”: “>=7.1”?
  3. After the composer update, committing the code changes to our server will solve all the deprecation errors ?

{
“name”: “roots/sage”,
“type”: “wordpress-theme”,
“license”: “MIT”,
“description”: “WordPress starter theme with a modern development workflow”,
“homepage”: “Sage | WordPress Starter Theme with Tailwind CSS & Blade | Roots”,
“authors”: [
{
“name”: “Ben Word”,
“email”: “ben@benword.com”,
“homepage”: “https://github.com/retlehs”
},
{
“name”: “Scott Walkinshaw”,
“email”: “scott.walkinshaw@gmail.com”,
“homepage”: “https://github.com/swalkinshaw”
},
{
“name”: “QWp6t”,
“email”: “hi@qwp6t.me”,
“homepage”: “https://github.com/qwp6t”
}
],
“keywords”: [“wordpress”],
“support”: {
“issues”: “https://github.com/roots/sage/issues”,
“forum”: “https://discourse.roots.io/”
},
“autoload”: {
“psr-4”: {
“App\”: “app/”
}
},
“repositories”: [
{ “type”: “vcs”, “url”: “https://github.com/jeh5256/sage-installer”},
{ “type”:“vcs”, “url”:“https://github.com/jeh5256/sage-lib” }
],
“require”: {
“php”: “>=7.1”,
“composer/installers”: “~2.0”,
“illuminate/support”: “^8.0”,
“roots/sage-lib”: “dev-master”,
“soberwp/controller”: “~2.1.0”
},
“require-dev”: {
“squizlabs/php_codesniffer”: “^2.8.0”,
“roots/sage-installer”: “dev-master”
},
“scripts”: {
“test”: [“phpcs”],
“post-create-project-cmd”: [
“Roots\Sage\Installer\ComposerScript::postCreateProject”
]
}
}

Kindly let me know.
Thanks.

I’ll try to answer in Bens stead.

To summarize, I think you will have to test for yourself to get the correct answers to your questions.

  1. What have you tried so far? I would try with the examples posted in the linked thread and then take it from there. It is basically impossible for anyone but you to know what will work in your specific setup. Take care to keep, and possibly update, any extra packages that may have been added in your current composer.json. Also take care to read all the posts in the thread as there are some questions and answers in it. FWIW, I have managed to upgrade a couple of Sage9-sites using the linked thread as a starting point but I always had to make adjustments to fit my needs and conditions.

  2. Since 8.2 is >=7.1, you probably don’t have to change this. But I would do it anyway and set it to >=8.2 if that is what you want to run under. If this does not work, you may have to change it back. There are some posts in the linked thread about this as well.

  3. If the remote server is running the same PHP-version as your dev-environment and it works in dev, it should work on remote as well, yes. But there may be other things that come into play and I would not recommend updating PHP on a prod server/environment and push the changes before you try it on a staging server/environment with the same setup as you intend to update prod to. If the prod environment is not business critical, by all means, go ahead and update it without testing first. It’s up to you :slight_smile:

Also, please read How to best ask questions on this forum and especially about formatting code and avoiding screenshots.

2 Likes

Hi,

I did the following steps.

  1. Update composer json file
  2. Ran composer update

It is showing below and asking token.

The “composer/installers” plugin was skipped because it requires a Plugin API version (“^1.0”) that does not match your Composer installation (“2.3.0”). You may need to run composer update with the “–no-plugins” option.
Loading composer repositories with package information
GitHub API limit (0 calls/hr) is exhausted, could not fetch https://api.github.com/repos/jeh5256/sage-installer. Create a GitHub OAuth token to go over the API rate limit. You can also wait until ? for the rate limit to reset.

When working with public GitHub repositories only, head to https://github.com/settings/tokens/new?scopes=&description=Composer+on+DESKTOP-6DCLAVQ+2024-01-24+1214 to retrieve a token.
This token will have read-only permission for public information only.
When you need to access private GitHub repositories as well, go to https://github.com/settings/tokens/new?scopes=repo&description=Composer+on+DESKTOP-6DCLAVQ+2024-01-24+1214
Note that such tokens have broad read/write permissions on your behalf, even if not needed by Composer.
Tokens will be stored in plain text in “C:/Users/CSS/AppData/Roaming/Composer/auth.json” for future use by Composer.
For additional information, check https://getcomposer.org/doc/articles/authentication-for-private-packages.md#github-oauth
Token (hidden):


What is the token and how to complete this step?

Click on the links you provided to get your answers. Let us know if you have additional questions!

Hi,

I have seen the token generation page. For the public repo, the link is Sign in to GitHub · GitHub

In that, what are the options should i need to choose?? - https://prnt.sc/DxbXCHw_FF9v

After generating token from that link, i will enter that token in cmd and run. Hope the composer update will get finish.
Thanks.

Odd, normally clicking on the link Composer provides for that pre-populates the “repo” checkbox

Hi,
Successfully ran composer update command.
After committing the files to server, it is displaying errors Screenshot by Lightshot

Any solution for this?