Problem/Motivation

In \Drupal\error_test\Controller\ErrorTestController::generateWarnings() we do

$bananas = [];
$monkey_love = $bananas[1];

To generate a notice - this produces a warning PHP 8.0.

Steps to reproduce

https://3v4l.org/2oaL1

Proposed resolution

Move to code that produces a notice in all situations.

$notice = new \stdClass();
$notice == 1 ? 1 : 0;

https://3v4l.org/r1WNq

Remaining tasks

User interface changes

None

API changes

None

Data model changes

None

Release notes snippet

None

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alexpott created an issue. See original summary.

andypost’s picture

Maybe it should just throw expectable warning instead of to be language specific?

alexpott’s picture

@andypost this has to be a language level warning. You can't throw that.

dawehner’s picture

Reading up on the RFC:
The object to scalar comparison is one of the ones which keep being a notice.

dawehner’s picture

As a comparison this is what symfony does in its error handling: https://github.com/symfony/error-handler/blob/5.x/Tests/ErrorHandlerTest...

andypost’s picture

alexpott’s picture

@dawehner @andypost we have a warning for PHP 7 & 8 already... we need something that is a notice on both. I don't understand why we need to copy symfony here.

andypost’s picture

Status: Needs review » Reviewed & tested by the community

This is critical blocker, so should be ready as our controller should provide language level warning as Symfony tests do more precise testing of specifics

alexpott’s picture

Re

Symfony tests do more precise testing of specifics

The purpose of \Drupal\error_test\Controller\ErrorTestController::generateWarnings() is to generate a PHP notice, PHP warning and PHP user error - to test how our error handler responds in those cases. Adding something like https://github.com/symfony/error-handler/blob/5.x/Tests/ErrorHandlerTest... to our test would mean that we'd lose PHP notice coverage in PHP 8 which is exactly what this issue is trying to (and successfully) avoiding.

andypost’s picture

I was more about why this test is functional but Alex reminded me about mess in error handlers and we should do real requests (instead of kernel/unit test as SF doing), also we using exceptions in core instead of "goto" so there's issues like #2638686: Exception in EarlyRenderingControllerWrapperSubscriber is a DX nightmare, remove it

SO this test should remain functional with the same error message on php 7 and 8

  • xjm committed d678245 on 9.2.x
    Issue #3177557 by alexpott, andypost, dawehner: \Drupal\error_test\...

  • xjm committed 947ba5b on 9.1.x
    Issue #3177557 by alexpott, andypost, dawehner: \Drupal\error_test\...

  • xjm committed df91ebe on 9.0.x
    Issue #3177557 by alexpott, andypost, dawehner: \Drupal\error_test\...
xjm’s picture

Version: 9.2.x-dev » 8.9.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)
Issue tags: +Needs followup

I think this is an acceptable fix for this, although I think we should add code comments documenting what's needed a little better (to reflect the discussion on this issue). That can be a followup, though.

As a test change, this is eligible for backport including to the production branch, and of course as a PHP 8 blocker it's a priority during the 9.1 alpha.

Committed to 9.2.x, 9.1.x, and 9.0.x. I didn't backport it to 8.9.x yet because I want to run tests against that first. Thanks!

xjm’s picture

Doesn't apply in any case, so if we did want to backport this to 8.9.x, we'd need a separate patch.

andypost’s picture

alexpott’s picture

Version: 8.9.x-dev » 9.0.x-dev
Status: Patch (to be ported) » Fixed

Given the agreement on #3156651: Prevent Drupal 8.9 and 9.0 from being installed on PHP 8 this won't need a backport at this point.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.