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

Issue fork drupal-3054072

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

alexpott created an issue. See original summary.

neeravbm’s picture

Issue summary: View changes
neeravbm’s picture

StatusFileSize
new4.19 KB

Patch 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.

alexpott’s picture

  1. +++ core/lib/Drupal/Component/Assertion/Handle.php	(date 1557724628000)
    @@ -2,6 +2,8 @@
    +@trigger_error('The ' . __NAMESPACE__ . '\Handle is deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Instead, replace the calls to Handle::register() method with assert_options(ASSERT_EXCEPTION, TRUE).', E_USER_DEPRECATED);
    
    @@ -10,6 +12,12 @@
    + * @see https://www.drupal.org/project/drupal/issues/3054072
    

    Needs to point to the change record and not the issue. They can be created from here - https://www.drupal.org/list-changes/drupal

  2. +++ core/tests/bootstrap.php	(date 1557724401000)
    @@ -182,10 +182,9 @@
    +// runtime assertions. By default this setting is on. This call does not turn
    +// runtime assertions on if they weren't on already.
    

    The This call does not turn runtime assertions on if they weren't on already is not necessary because we're no longer calling any of our own code here and it is obvious we're not setting assert.active because we're setting ASSERT_EXCEPTION.

alexpott’s picture

Status: Active » Postponed

This needs to be postponed until #3053363: Remove support for PHP 5 in Drupal 8.8 lands. Reviews on that issue more than welcome!

alexpott’s picture

Status: Postponed » Needs work

The blocker is in!

yogeshmpawar’s picture

Assigned: Unassigned » yogeshmpawar
yogeshmpawar’s picture

Assigned: yogeshmpawar » Unassigned
Status: Needs work » Needs review
StatusFileSize
new3.35 KB

Comments addressed in #4 & also re-rolled the patch against 8.8.x branch.

berdir’s picture

Status: Needs review » Needs work

Looks 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.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

br0ken’s picture

Status: Needs work » Needs review
krzysztof domański’s picture

Version: 8.9.x-dev » 9.1.x-dev
Status: Needs review » Needs work

Issues adding new deprecations (for removal in Drupal 10) should be moved to 9.1.x

Drupal 8.8 was the final release to introduce new deprecations that will be removed in Drupal 9. This means that all new deprecations in 8.9 and higher will be retained in Drupal 9 and marked for removal in Drupal 10 instead.

br0ken’s picture

@Krzysztof Domański, why back to NW?

krzysztof domański’s picture

+@trigger_error('The ' . __NAMESPACE__ . '\Handle is deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Instead, replace the calls to Handle::register() method with assert_options(ASSERT_EXCEPTION, TRUE).', E_USER_DEPRECATED);
+ * @deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0.

1. 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.

all new deprecations in 8.9 and higher will be retained in Drupal 9 and marked for removal in Drupal 10 instead.

2. See also what is the correct the PHPdoc text and trigger_error() message format on the Drupal core deprecation policy.

br0ken’s picture

Status: Needs work » Needs review
StatusFileSize
new4.34 KB

Thanks. CR updated.

br0ken’s picture

StatusFileSize
new4.34 KB
new1.01 KB

Oops.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

neclimdul’s picture

StatusFileSize
new3.45 KB

re-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.

neclimdul’s picture

StatusFileSize
new1.05 KB
new3.45 KB

Sorry for the noise, I forgot to update the deprecation message.

longwave’s picture

It seems a bit pointless here but we usually have a test for deprecation messages.

neclimdul’s picture

StatusFileSize
new4.57 KB
new2.19 KB

Yeah, maybe a little pointless but doable so test included. Also the style fix.

neclimdul’s picture

StatusFileSize
new4.56 KB

Woops... some whitespace errors.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

longwave’s picture

Status: Needs review » Needs work

#23 is good for 9.4.x but needs a separate version for 10.0.x as core/tests/bootstrap.php has changed.

voleger made their first commit to this issue’s fork.

longwave’s picture

Oh 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?

voleger’s picture

Status: Needs work » Needs review

Added deprecation removal for 10.x
Updated deprecation messages for 9.4.x

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

catch’s picture

So 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.

spokje’s picture

Version: 9.5.x-dev » 10.0.x-dev
Status: Needs review » Needs work

Bumping 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:

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.

ravi.shankar’s picture

StatusFileSize
new3.46 KB

Added a patch for Drupal 10.0.x.

ravi.shankar’s picture

Status: Needs work » Needs review

Patch #34 passes the tests and It's green, It's ready for review.

xjm’s picture

Version: 10.0.x-dev » 10.1.x-dev
Status: Needs review » Needs work

Based 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.

arunkumark’s picture

Status: Needs work » Needs review
StatusFileSize
new2.5 KB

As per comment #36, patch #34 has been re-rolled to work Drupal on 10.1.x

catch’s picture

Status: Needs review » Needs work
+++ /dev/null
@@ -1,25 +0,0 @@
- * Handler for runtime assertion failures.
- *
- * @ingroup php_assert
- *
- * @todo Deprecate this class. https://www.drupal.org/node/3054072
- */
-class Handle {

This 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.

spokje’s picture

Status: Needs work » Needs review
StatusFileSize
new2.6 KB
longwave’s picture

Status: Needs review » Reviewed & tested by the community

#39 looks correct to me for 10.1.x only.

catch’s picture

Status: Reviewed & tested by the community » Needs review
+++ b/core/lib/Drupal/Component/Assertion/Handle.php
@@ -2,12 +2,17 @@
 
+@trigger_error(__NAMESPACE__ . '\Handle is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Instead, use assert_options(ASSERT_EXCEPTION, TRUE). See https://drupal.org/node/3105918', E_USER_DEPRECATED);
+

One 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.

arunkumark’s picture

StatusFileSize
new2.28 KB

Updated patch by removing the @trigger_error

longwave’s picture

Status: Needs review » Needs work

What @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.

Ratan Priya’s picture

Assigned: Unassigned » Ratan Priya
Ratan Priya’s picture

Assigned: Ratan Priya » Unassigned
Status: Needs work » Needs review
StatusFileSize
new2.6 KB
new9.15 KB

@longwave,

I made the changes you required at comments #43

Needs review.

voleger’s picture

Status: Needs review » Reviewed & tested by the community

#43 was addressed, looks good

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 29531e2 and pushed to 10.1.x. Thanks!

diff --git a/core/lib/Drupal/Component/Assertion/Handle.php b/core/lib/Drupal/Component/Assertion/Handle.php
index e682ccaeae..7ef456c505 100644
--- a/core/lib/Drupal/Component/Assertion/Handle.php
+++ b/core/lib/Drupal/Component/Assertion/Handle.php
@@ -9,8 +9,8 @@
  *
  * @ingroup php_assert
  *
- * @deprecated in drupal:10.1.0 and is removed from drupal:11.0.0.
- * Use assert_options(ASSERT_EXCEPTION, TRUE).
+ * @deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use
+ *   assert_options(ASSERT_EXCEPTION, TRUE).
  *
  * @see https://www.drupal.org/node/3105918
  */

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.

+++ b/core/lib/Drupal/Component/Assertion/Handle.php
@@ -2,12 +2,17 @@
+trigger_error(__NAMESPACE__ . '\Handle is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Instead, use assert_options(ASSERT_EXCEPTION, TRUE). See https://drupal.org/node/3105918', E_USER_DEPRECATED);

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.

  • alexpott committed 29531e2 on 10.1.x
    Issue #3054072 by voleger, neclimdul, BR0kEN, arunkumark, Ratan Priya,...

Status: Fixed » Closed (fixed)

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

andypost’s picture

With PHP 8.3 the assert_options() is deprecated, looking for opinions in #3375693: Fix deprecated assert_options() function usage for PHP 8.3