craftcms / cms

Build bespoke content experiences with Craft.
https://craftcms.com
Other
3.28k stars 635 forks source link

[3.x]: Deprecation errors using PHP 8.1 and Craft 3.9 #13717

Closed jamiematrix closed 1 year ago

jamiematrix commented 1 year ago

What happened?

Description

Migrating a site to AWS that has PHP 8.1. Locally I had the site on PHP 8.0 and all looked well. Updated to PHP 8.1 and now get a load of deprecation warnings:

Deprecated: Return type of Tightenco\Collect\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 /var/www/html/vendor/tightenco/collect/src/Collect/Support/Collection.php on line 1789

Deprecated: Return type of Tightenco\Collect\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 /var/www/html/vendor/tightenco/collect/src/Collect/Support/Collection.php on line 1800

Deprecated: Return type of Tightenco\Collect\Support\Collection::offsetSet($key, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/vendor/tightenco/collect/src/Collect/Support/Collection.php on line 1812

Deprecated: Return type of Tightenco\Collect\Support\Collection::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/vendor/tightenco/collect/src/Collect/Support/Collection.php on line 1827

Deprecated: Return type of Tightenco\Collect\Support\Collection::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/vendor/tightenco/collect/src/Collect/Support/Collection.php on line 1768

Deprecated: Return type of Tightenco\Collect\Support\Collection::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/vendor/tightenco/collect/src/Collect/Support/Collection.php on line 1747

Deprecated: Return type of Tightenco\Collect\Support\Collection::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/vendor/tightenco/collect/src/Collect/Support/Collection.php on line 1716

Deprecated: auto_detect_line_endings is deprecated in /var/www/html/vendor/vlucas/phpdotenv/src/Loader.php on line 172

These appear on all pages including admin ones.

When this happens I'm not able to see 90% of the site content in /admin. No entries are listed, no categories, assets, users, etc. All of them are blank. As soon as I downgrade to PHP 8.0 they appear. Also not able to load the updates page

Steps to reproduce

  1. Run site on PHP 8.1
  2. See warnings

Expected behavior

Not see the warnings

Actual behavior

See a load of deprecation warnings.

Craft CMS version

3.9.3

PHP version

8.1

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

-

jamiematrix commented 1 year ago

Digging further it appears to be the plugin "Craft Notifcations" Craft Notifcations. Removing that for now has cleared all but 1 warning. I now just get

Deprecated: auto_detect_line_endings is deprecated in /var/www/html/vendor/vlucas/phpdotenv/src/Loader.php on line 172

Entries etc are still not loading

jamiematrix commented 1 year ago

Found this issue and updated the vlucas/phpdotenv to ^5.4 and now getting:

Fatal error: Uncaught TypeError: Dotenv\Dotenv::__construct(): Argument #1 ($store) must be of type Dotenv\Store\StoreInterface, string given, called in /var/www/html/web/index.php on line 15 and defined in /var/www/html/vendor/vlucas/phpdotenv/src/Dotenv.php:60 Stack trace: #0 /var/www/html/web/index.php(15): Dotenv\Dotenv->__construct('/var/www/html') #1 {main} thrown in /var/www/html/vendor/vlucas/phpdotenv/src/Dotenv.php on line 60

Guessing Craft 3.x doesn't support that high version?

jamiematrix commented 1 year ago

I found this helpful answer which seems to have done the trick for me.

Does none of the above happen during any updates? The site went from Craft 3.4 to 3.9 using the CLI to run the updates

i-just commented 1 year ago

Glad you got it sorted!

You can find a bit more info about what happens during updates here: https://github.com/craftcms/cms/issues/12447#issuecomment-1352720402

brandonkelly commented 1 year ago

Does none of the above happen during any updates? The site went from Craft 3.4 to 3.9 using the CLI to run the updates

No, phpDotenv is a library that is required at the project level, not by Craft itself, as Craft has no direct need for it (there are multiple ways to set environment variables). So it’s up to you to keep it updated.