Problem/Motivation
Once #3053363: Remove support for PHP 5 in Drupal 8.8 lands \Drupal\Component\Assertion\Handle::register() is kind of pointless.
Proposed resolution
- Create a change record
- Deprecate the entire class
- Replace calls to it with
assert_options(ASSERT_EXCEPTION, TRUE);
The assert_options(ASSERT_WARNING, FALSE); is pointless. If you have assert_options(ASSERT_EXCEPTION, TRUE); on, no warnings are produced by the following code:
assert_options(ASSERT_WARNING, TRUE);
assert_options(ASSERT_EXCEPTION, TRUE);
assert(TRUE == FALSE);
Remaining tasks
User interface changes
None
API changes
\Drupal\Component\Assertion\Handle is deprecated
Data model changes
None
Release notes snippet
Comments
Comment #2
neeravbm commentedComment #3
neeravbm commentedPatch attached that does the following:
1) Adds @trigger_error, @deprecated and @see in Drupal/Component/Assertion/Handle class.
2) Replaces calls to Handle::register() function with assert_options(ASSERT_EXCEPTION, TRUE);
Still need to add the change notice.
Comment #4
alexpottNeeds to point to the change record and not the issue. They can be created from here - https://www.drupal.org/list-changes/drupal
The
This call does not turn runtime assertions on if they weren't on alreadyis not necessary because we're no longer calling any of our own code here and it is obvious we're not settingassert.activebecause we're settingASSERT_EXCEPTION.Comment #5
alexpottThis needs to be postponed until #3053363: Remove support for PHP 5 in Drupal 8.8 lands. Reviews on that issue more than welcome!
Comment #6
alexpottThe blocker is in!
Comment #7
yogeshmpawarComment #8
yogeshmpawarComments addressed in #4 & also re-rolled the patch against 8.8.x branch.
Comment #9
berdirLooks like we still need to create a change record although I feel like there's not more to say than what the comment already does. However, because it is in example.settings.local.php, I suspect this will actually affect *a lot* of dev installations, so the additional visibility seems useful.
Comment #11
br0kenHere's the draft - https://www.drupal.org/node/3105918.
Comment #12
krzysztof domańskiIssues adding new deprecations (for removal in Drupal 10) should be moved to 9.1.x
Comment #13
br0ken@Krzysztof Domański, why back to NW?
Comment #14
krzysztof domański1. It won't be backported to D8.8 so it should be
deprecated in drupal:9.1.0 and is removed from drupal:10.0.0.2. See also what is the correct the PHPdoc text and trigger_error() message format on the Drupal core deprecation policy.
Comment #15
br0kenThanks. CR updated.
Comment #16
br0kenOops.
Comment #19
neclimdulre-roll around #3110862: Remove simpletest module from core and #3063182: Remove PHPUnit 4.8 class aliasing BC layer and who knows how many other little use changes.
Comment #20
neclimdulSorry for the noise, I forgot to update the deprecation message.
Comment #21
longwaveIt seems a bit pointless here but we usually have a test for deprecation messages.
Comment #22
neclimdulYeah, maybe a little pointless but doable so test included. Also the style fix.
Comment #23
neclimdulWoops... some whitespace errors.
Comment #25
longwave#23 is good for 9.4.x but needs a separate version for 10.0.x as core/tests/bootstrap.php has changed.
Comment #29
longwaveOh we will need to update the version to 9.4.x, can we still remove this in 10.0.x as it seems unlikely to be used outside of core?
Comment #30
volegerAdded deprecation removal for 10.x
Updated deprecation messages for 9.4.x
Comment #32
catchSo most new deprecations now should be for 10.1.x for removal in 11.x, but I think there's a couple of good reasons to do something here before that:
1. We have docs telling people to use this in example.settings.local.php - at a minimum those docs should be updated to not recommend it if we know we're going to remove it.
2. This is part of updating the platform requirements.
3. There shouldn't be any contrib impact at all.
I was about to write that given the above, we should deprecate in 9.5.0 for removal in 11.0.0, but... if people are using that settings.local.php snippet, are we suddenly going to start triggering a deprecation error on every request? That seems annoying for the last minor release. And then, given the deprecation error is suppressed and no-one runs phpstan on settings.local.php, what is the deprecation error going to do there? We probably need something stronger.
So... I am not sure what to do here. I kind of feel like we should add an un-suppressed deprecation error in 10.0.x or 10.1.x, specifically to loudly warn people that they need to sort out their settings.local.php so they don't get a fatal error when the update to Drupal 11. But that is unusual so more opinions would be good.
Regardless, I think it would be a good idea to commit a minimal patch changing settings.local.php so we stop recommending this, maybe even back to 9.4.x.
Comment #33
spokjeBumping this one to 10.0.x (for now).
Opened #3295650: Stop recommending using \Drupal\Component\Assertion\Handle::register() in example.settings.local.php to deal with:
Comment #34
ravi.shankar commentedAdded a patch for Drupal 10.0.x.
Comment #35
ravi.shankar commentedPatch #34 passes the tests and It's green, It's ready for review.
Comment #36
xjmBased on #32 I think this part of it should be 10.1.x; thanks for splitting off #3295650: Stop recommending using \Drupal\Component\Assertion\Handle::register() in example.settings.local.php.
Comment #37
arunkumarkAs per comment #36, patch #34 has been re-rolled to work Drupal on 10.1.x
Comment #38
catchThis should be deprecated (in 10.1.x for removal in 11.0.0, not removed - I think the 9.x patches in this issue already did that.
Comment #39
spokjeComment #40
longwave#39 looks correct to me for 10.1.x only.
Comment #41
catchOne more question - should we remove the @ here so that actual sites get the deprecation message (if they're running E_DEPRECATED) - because this is most likely to be loaded from settings.local.php which doesn't get test covrage.
Comment #42
arunkumarkUpdated patch by removing the @trigger_error
Comment #43
longwaveWhat @catch meant in #41 was to leave the
trigger_error()line in place, just remove the@at the start of the line so the deprecation is not silenced.Comment #44
Ratan Priya commentedComment #45
Ratan Priya commented@longwave,
I made the changes you required at comments #43
Needs review.
Comment #46
voleger#43 was addressed, looks good
Comment #47
alexpottCommitted 29531e2 and pushed to 10.1.x. Thanks!
We should re-flow the comment so it's all part of the @deprecated - i.e. the next line needs to be indented. Fixed on commit.
I'm not sure about not silencing this - that means if there is code calling this we will produce noisy deprecations. I can see the discussion around example.settings.local.php but maybe there is other code out there that will immediately become noisy. I think that maybe we should silence it and rely on phpstan to find this for sites. OTOH this is mostly likely being called in dev situations so he noisiness is not problematic and might be even welcome. Decided to proceed as is. We can always silence it later.
Comment #50
andypostWith PHP 8.3 the
assert_options()is deprecated, looking for opinions in #3375693: Fix deprecated assert_options() function usage for PHP 8.3