Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 8.1 Support #4385

Closed
c-schmitz opened this issue Dec 1, 2021 · 32 comments
Closed

PHP 8.1 Support #4385

c-schmitz opened this issue Dec 1, 2021 · 32 comments

Comments

@c-schmitz
Copy link
Contributor

c-schmitz commented Dec 1, 2021

What steps will reproduce the problem?

Execute any component that uses CList.

What is the expected result?

No errors

What do you get instead?

These errors:

<b>Fatal error</b>: During inheritance of IteratorAggregate: Uncaught Error: Class "CList" not found in \htdocs\app\framework\base\CComponent.php:474 Stack trace: #0 \htdocs\app\framework\base\CComponent.php(516): CComponent-&gt;getEventHandlers('onbeginrequest') #1 \htdocs\app\framework\web\CHttpRequest.php(146): CComponent-&gt;attachEventHandler('onBeginRequest', Array) #2 \htdocs\app\application\core\LSHttpRequest.php(151): CHttpRequest-&gt;normalizeRequest() #3 \htdocs\app\framework\web\CHttpRequest.php(119): LSHttpRequest-&gt;normalizeRequest() #4 \htdocs\app\framework\base\CModule.php(394): CHttpRequest-&gt;init() #5 \htdocs\app\framework\base\CModule.php(103): CModule-&gt;getComponent('request') #6 \htdocs\app\framework\base\CErrorHandler.php(292): CModule-&gt;__get('request') #7 \htdocs\app\framework\base\CErrorHandler.php(133): CErrorHandler-&gt;handleError(Object(CErrorEvent)) #8 \htdocs\app\framework\base\CApplication.php(834): CErrorHandler-&gt;handle(Object(CErrorEvent)) #9 \htdocs\app\framework\collections\CList.php(38): CApplication-&gt;handleError(8192, 'Return type of ...', 'htdocs...', 88) #10 \htdocs\app\framework\YiiBase.php(437): include('htdocs...') #11 \htdocs\app\framework\base\CComponent.php(474): YiiBase::autoload('CList') #12 \htdocs\app\framework\base\CComponent.php(516): CComponent-&gt;getEventHandlers('onflush') #13 \htdocs\app\framework\logging\CLogRouter.php(69): CComponent-&gt;attachEventHandler('onFlush', Array) #14 \htdocs\app\framework\base\CModule.php(394): CLogRouter-&gt;init() #15 \htdocs\app\framework\base\CModule.php(530): CModule-&gt;getComponent('log') #16 \htdocs\app\framework\base\CApplication.php(168): CModule-&gt;preloadComponents() #17 \htdocs\app\application\core\LSYii_Application.php(91): CApplication-&gt;__construct(Array) #18 \htdocs\app\framework\YiiBase.php(132): LSYii_Application-&gt;__construct(Array) #19 \htdocs\app\index.php(192): YiiBase::createApplication('LSYii_Applicati...', Array) #20 {main} in <b>\htdocs\app\framework\collections\CList.php</b> on line <b>38</b><br>

Error log:

[Wed Dec 01 08:54:35.671111 2021] [php:error] [pid 15508:tid 1860] [client 127.0.0.1:55343] PHP Fatal error: During inheritance of IteratorAggregate: Uncaught Error: Class "CList" not found in \htdocs\app\framework\base\CComponent.php:474\nStack trace:\n#0 \htdocs\app\framework\base\CComponent.php(516): CComponent->getEventHandlers('onbeginrequest')\n#1 \htdocs\app\framework\web\CHttpRequest.php(146): CComponent->attachEventHandler('onBeginRequest', Array)\n#2 \htdocs\app\application\core\LSHttpRequest.php(151): CHttpRequest->normalizeRequest()\n#3 \htdocs\app\framework\web\CHttpRequest.php(119): LSHttpRequest->normalizeRequest()\n#4 \htdocs\app\framework\base\CModule.php(394): CHttpRequest->init()\n#5 \htdocs\app\framework\base\CModule.php(103): CModule->getComponent('request')\n#6 \htdocs\app\framework\base\CErrorHandler.php(292): CModule->__get('request')\n#7 \htdocs\app\framework\base\CErrorHandler.php(133): CErrorHandler->handleError(Object(CErrorEvent))\n#8 \htdocs\app\framework\base\CApplication.php(834): CErrorHandler->handle(Object(CErrorEvent))\n#9 \htdocs\app\framework\collections\CList.php(38): CApplication->handleError(8192, 'Return type of ...', 'C:\\xampp\\htdocs...', 88)\n#10 \htdocs\app\framework\YiiBase.php(437): include('C:\\xampp\\htdocs...')\n#11 \htdocs\app\framework\base\CComponent.php(474): YiiBase::autoload('CList')\n#12 \htdocs\app\framework\base\CComponent.php(516): CComponent->getEventHandlers('onflush')\n#13 \htdocs\app\framework\logging\CLogRouter.php(69): CComponent->attachEventHandler('onFlush', Array)\n#14 \htdocs\app\framework\base\CModule.php(394): CLogRouter->init()\n#15 \htdocs\app\framework\base\CModule.php(530): CModule->getComponent('log')\n#16 \htdocs\app\framework\base\CApplication.php(168): CModule->preloadComponents()\n#17 \htdocs\app\application\core\LSYii_Application.php(91): CApplication->__construct(Array)\n#18 \htdocs\app\framework\YiiBase.php(132): LSYii_Application->__construct(Array)\n#19 \htdocs\app\index.php(192): YiiBase::createApplication('LSYii_Applicati...', Array)\n#20 {main} in \htdocs\app\framework\collections\CList.php on line 38 [Wed Dec 01 08:55:44.365549 2021] [php:notice] [pid 15508:tid 1860] [client 127.0.0.1:55371] PHP Deprecated: Return type of CMap::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in \htdocs\app\framework\collections\CMap.php on line 81 [Wed Dec 01 08:55:44.365549 2021] [php:notice] [pid 15508:tid 1860] [client 127.0.0.1:55371] PHP Deprecated: Return type of CMap::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in \htdocs\app\framework\collections\CMap.php on line 306 [Wed Dec 01 08:55:44.365549 2021] [php:notice] [pid 15508:tid 1860] [client 127.0.0.1:55371] PHP Deprecated: Return type of CMap::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in \htdocs\app\framework\collections\CMap.php on line 317 [Wed Dec 01 08:55:44.366549 2021] [php:notice] [pid 15508:tid 1860] [client 127.0.0.1:55371] PHP Deprecated: Return type of CMap::offsetSet($offset, $item) 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 \htdocs\app\framework\collections\CMap.php on line 328 [Wed Dec 01 08:55:44.366549 2021] [php:notice] [pid 15508:tid 1860] [client 127.0.0.1:55371] PHP Deprecated: Return type of CMap::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in \htdocs\app\framework\collections\CMap.php on line 338 [Wed Dec 01 08:55:44.366549 2021] [php:notice] [pid 15508:tid 1860] [client 127.0.0.1:55371] PHP Deprecated: Return type of CMap::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in \htdocs\app\framework\collections\CMap.php on line 91

Additional info

Q A
Yii version 1.1.24
PHP version 8.1.0
Operating system Windows
@marcovtwout
Copy link
Member

marcovtwout commented Dec 1, 2021

Extracted the source deprecation errors from your log:

PHP Deprecated: Return type of CMap::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in \htdocs\app\framework\collections\CMap.php on line 81
PHP Deprecated: Return type of CMap::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in \htdocs\app\framework\collections\CMap.php on line 306
PHP Deprecated: Return type of CMap::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in \htdocs\app\framework\collections\CMap.php on line 317
PHP Deprecated: Return type of CMap::offsetSet($offset, $item) 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 \htdocs\app\framework\collections\CMap.php on line 328
PHP Deprecated: Return type of CMap::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in \htdocs\app\framework\collections\CMap.php on line 338
PHP Deprecated: Return type of CMap::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in \htdocs\app\framework\collections\CMap.php on line 91

This likely affects a whole ranges of classes that implement standard interfaces.

See https://www.php.net/manual/en/migration81.incompatible.php#migration81.incompatible.core.type-compatibility-internal

@marcovtwout
Copy link
Member

marcovtwout commented Dec 1, 2021

@marcovtwout marcovtwout mentioned this issue Dec 1, 2021
6 tasks
@kenguest
Copy link
Contributor

kenguest commented Dec 3, 2021

would running appropriate incantations of rectorphp over the framework code suffice?

@marcovtwout
Copy link
Member

@kenguest Not probably - as we strive to keep all changes backwards compatible. It could help with listing issues though.

@kenguest
Copy link
Contributor

kenguest commented Dec 8, 2021

what's the minimum version of php that compatibility has to be kept with? I seriously doubt it's PHP 5.1 as per the composer file

@c-schmitz
Copy link
Contributor Author

c-schmitz commented Dec 8, 2021

For the minimum version question, I would recommend to use as a benchmark the oldest still-supported Ubuntu LTS (that is 18.04.x)- which is using a maintained version of PHP 7.2.x.
That would also address the PHPUnit issue (which I think requires PHP 7.2.5 as a minimum)

@samdark
Copy link
Member

samdark commented Dec 8, 2021

@kenguest it is what's stated in composer file but we actively test on 5.3+: https://github.com/yiisoft/yii/blob/master/.github/workflows/build.yml#L23

@marcovtwout
Copy link
Member

marcovtwout commented Dec 8, 2021

On paper Yii 1 should work on PHP 5.1, and tests are running from PHP 5.3 and up. Note that there are distributions such as Debian that will backport fixes to outdated PHP versions, for example Debian 9 LTS still supports PHP 7.0. And Ubuntu LTS has ESM that seems to go back to 14.04 with PHP 5.5.

Bumping the minimum PHP version should be a separate discussion from this issue, as this is meant to list the problems that we need to fix. However in short my view on things: We should strive to keep this project backwards compatible for outdated and unsupported PHP versions, until it becomes blocking or really unpractical for those keeping their projects and PHP-versions up to date. One example is PHPUnit compatibility (#4366) and future PHP major releases will probably require breaking changes as well. I'd like to stay away from clumsy solutions such as patch files or import tricks in order to keep supporting those really old versions. I think at some point bumping minimum versions has to be done.

@c-schmitz
Copy link
Contributor Author

Hi, is there any ETA on a fix? (just asking, no pressure)

@samdark
Copy link
Member

samdark commented Dec 10, 2021

@c-schmitz no, not yet.

@marcovtwout
Copy link
Member

@c-schmitz Not only Yii core code has to be updated, probably some third party stuff as well. Since PHP 8.1 is only recently stable it could take a while until all the issues are known. I'll probably wait until most of the issues are reported here. Also we'll keep an eye on when yiisoft/yii2#19041 is finished before applying fixes here, so we can choose a similar strategy.

@twisted1919
Copy link
Contributor

I'll probably wait until most of the issues are reported here.

Problem with this approach is that we can't test PHP 8.1 because of the above mentioned problems which simply block our applications from running on that PHP version. Maybe you should start merging fixes in master so we can at least test them and advance with finding new issues in our day to day usage? It's an idea.

As for the minimum PHP version, it's a tricky one. I don't think people are using PHP 5.x with Yii tbh, but what are the options to block this current Yii 1.1.x version for PHP 5.3 as your guarantee stands, and then the next update to require PHP >= 7.0 and apply all the fixes to it? I believe this can be achieved via composer version constraints.

@c-schmitz
Copy link
Contributor Author

c-schmitz commented Mar 10, 2022

PHP 8.1 has been out for quite some while now. Is there currently any work done regarding this issue? I can see that there is a patch but it seems without activity for quite some time.

@marcovtwout
Copy link
Member

@twisted1919 Absolutely a valid point.

PHP 8.1 support for Yii 2 is completed (yiisoft/yii2#19041) and released a few weeks ago, with few reports since then as far as I can tell.

In week 13/14 (beginning of april) I have time scheduled to work on #4386 and apply most of the required changes. Then it can be used for further testing by the community.

@marcovtwout
Copy link
Member

@twisted1919 @c-schmitz @samdark I finished the groundwork on #4386 which fixes most of the known issues so far. I think it's good enough for be used by the community so they can test their applications to find additional issues.

Please report any new issues found here.

@twisted1919
Copy link
Contributor

@marcovtwout - Awesome!
Should we wait for you to merge in master and take it from there or should we take it from the php81-support branch?

@marcovtwout
Copy link
Member

@twisted1919 I'm expecting more issues to pop up during testing, since only so much is caught by the test suite. For now, please take it from https://github.com/yiisoft/yii/tree/php81-support

@samdark
Copy link
Member

samdark commented Apr 1, 2022

I'd merge it to master to get more feedback.

@marcovtwout
Copy link
Member

I'll think about that. I'd rather merge after at least a few people have tested my work in different scenario's, also at least one library is not compatible yet. If after a few weeks there is only limited feedback I'll merge to master what we have.

@valkars
Copy link

valkars commented Apr 11, 2022

Hello, I've tested branch php81-support in my project on php 8.1 - all works fine, all warnings and deprecations are gone. Will wait for the release or merge to master

@c-schmitz
Copy link
Contributor Author

Also tested here. Looks all fine. Would be great if it can be merged.

@twisted1919
Copy link
Contributor

Can we have this merged?

@marcovtwout
Copy link
Member

@twisted1919 I'm waiting for ezyang/htmlpurifier#311 to be released. If it takes too long, I'll use the htmlpurifier dev-version in the release, but I'd rather not if we can avoid it. Will set a reminder to recheck at the end of next month.

@c-schmitz
Copy link
Contributor Author

To be honest, I would not hold my breath for the HTMLPurifier release. Their last release is from 6 months ago and they seem to release very rarely.
Rather use dev for now so Yii1 can finally be fixed.

@marcovtwout
Copy link
Member

@c-schmitz Yes, I'm planning to integrate that and merge within the coming 2 weeks.

@juslintek
Copy link

Nice, would love that Yii 1.1 would support composer 4 autoloader as core namespaces handler, instead of using its own autoloading, based on dot notation. :-) So I could use modern namespaces everywhere and single autoloader would be responsible for loading them. I'm trying to implement some laravel and symfony features on my project and it requires quite a lot of core overriding and extending, to make this work, not only custom index.php, but custom App and bla bla, to autoload those framework features to be available for usage on yii core features.

@marcovtwout
Copy link
Member

@juslintek Your comment is off topic and those kind of changes won't happen. Perhaps this is helpful for you: https://www.yiiframework.com/doc/guide/1.1/en/basics.namespace#namespace

@marcovtwout
Copy link
Member

Please see #4386 (comment) for an update about htmlpurifier.

@marcovtwout
Copy link
Member

Fixed by #4386

@kenguest
Copy link
Contributor

kenguest commented Aug 10, 2022

This is fantastic - is there an ETA on when a new version with support for PHP 8.1 will be released? (I'm sorry to seem impatient, but this is too great to not have a proper release :-) )

@papppeter
Copy link

Please release it it would be great to have it!

@marcovtwout
Copy link
Member

Release planned for the end of september, you can use master until then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants