'Fatal error on Yii framework page on PHP 8.1

I just had this error when I updated to PHP 8.1:

Fatal Error: Cannot use 'Object' as a class name as it is reserved on line 77

I guess it used a reserved word as an actual class. How can I solve this?



Solution 1:[1]

You need to follow the instructions on this page to upgrade.
For example, to use php 7, 8, you must follow the instructions in this section.

For compatibiliy with PHP 7.2 which does not allow classes to be named Object anymore, we needed to rename yii\base\Object to yii\base\BaseObject.

This also applies to php 8.

Upgrade from Yii 2.0.12
If you want to upgrade PHP to version 7.2 in your project you need to remove all cases that extend yii\base\Object and extend from yii\base\BaseObject instead:

Good luck

Solution 2:[2]

The solution depends where exactly the error occurs.

Error is in file that belongs to Yii framework itself

You have to upgrade framework to newer version. Version 2.0.13 introduced yii\base\BaseObject as base class instead of yii\base\Object.

Error is in some 3rd party library

You have to look for upgrade of that library.

Error is in class that belongs directly to your application

That probably means that your class extends yii\base\Object. You have to modify classes like that to extend yii\base\BaseObject instead. This requires the version of Yii framework to be at least 2.0.13. But because the error didn't occur in framework its version should be probably ok.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Michal Hynčica