Remove mentions of assert.active from .htaccess

Created on 31 October 2023, about 1 year ago

Problem/Motivation

There's override of the setting https://git.drupalcode.org/project/drupal/-/blob/8f50a5caaf9585f15825dee... which should be removed as core no longer use this setting after πŸ“Œ Fix deprecated assert_options() function usage for PHP 8.3 Needs review

Steps to reproduce

- run apache2+mop_php
- check logs for value override, may need versole logging enabled
- make sure there's no deprecation message

Proposed resolution

remove mentions of the setting as its default value 1

Remaining tasks

- patch
- review
- commit

User interface changes

API changes

no

Data model changes

no

Release notes snippet

πŸ“Œ Task
Status

Active

Version

11.0 πŸ”₯

Component
BaseΒ  β†’

Last updated about 5 hours ago

Created by

πŸ‡«πŸ‡·France andypost

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @andypost
  • πŸ‡«πŸ‡·France andypost

    at CLI side

    /var/www/html/web $ php -v
    PHP 8.3.0RC5 (cli) (built: Oct 24 2023 23:57:57) (NTS)
    Copyright (c) The PHP Group
    Zend Engine v4.3.0RC5, Copyright (c) Zend Technologies
        with Zend OPcache v8.3.0RC5, Copyright (c), by Zend Technologies
    /var/www/html/web $ php -dassert.active=0 -r 'echo 1;'
    PHP Deprecated:  PHP Startup: assert.active INI setting is deprecated in Unknown on line 0
    1
  • Merge request !5201Remove mentions of assert.active #3398033 β†’ (Open) created by andypost
  • Pipeline finished with Success
    about 1 year ago
    Total: 650s
    #42063
  • Status changed to Needs review about 1 year ago
  • Status changed to RTBC about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Searched for assert.active in .htaccess and 1 instance has been replaced.

  • πŸ‡¬πŸ‡§United Kingdom catch

    Tagging for release notes because this should go in 'changes to site owner managed files'.

    Also tagging for a change record update because the one linked doesn't explicitly mention .htaccess yet.

  • Status changed to Needs work about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States darren oh Lakeland, Florida

    I agree with removing assert.active, but not with removing the documentation for adding PHP settings. I relied heavily on this documentation to get my sites working when I started out with Drupal.

  • Pipeline finished with Success
    about 1 year ago
    Total: 730s
    #68925
  • Pipeline finished with Success
    about 1 year ago
    Total: 620s
    #68933
  • Pipeline finished with Success
    about 1 year ago
    Total: 643s
    #68939
  • Pipeline finished with Success
    about 1 year ago
    Total: 575s
    #68942
  • Status changed to Needs review about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States darren oh Lakeland, Florida

    I restored the PHP settings documentation to the 11.x branch. I don't think assertions should be enabled by default in 10.x because they are used in contrib projects, so I added a merge request for 10.x that replaces assert.active with zend.assertions.

  • Pipeline finished with Success
    about 1 year ago
    Total: 724s
    #69162
  • Pipeline finished with Success
    about 1 year ago
    Total: 736s
    #69161
  • Status changed to RTBC about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Don't see any issue with leaving the comments. Think this missed 10.2 though.

  • Pipeline finished with Success
    about 1 year ago
    Total: 754s
    #70649
  • Pipeline finished with Failed
    about 1 year ago
    Total: 493s
    #70660
  • Pipeline finished with Canceled
    about 1 year ago
    Total: 75s
    #70669
  • πŸ‡ΊπŸ‡ΈUnited States darren oh Lakeland, Florida

    Darren Oh β†’ changed the visibility of the branch 3398033-remove-assert.active to hidden.

  • Pipeline finished with Success
    about 1 year ago
    Total: 532s
    #70667
  • Status changed to Needs review about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States darren oh Lakeland, Florida

    I don't think a default setting for assertions should be removed in Drupal 10. I switched the merge request for 10.2.x to 11.x and changed zend.assertions to a value that can be overridden in settings.local.php. Also updated the change record.

  • Status changed to Needs work about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Think 10.3 should be fine. But MR has a test failure now.

  • Pipeline finished with Failed
    about 1 year ago
    Total: 1299s
    #70671
  • Status changed to Needs review about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States darren oh Lakeland, Florida

    Didn't realize files in the sites folder were scaffolded.

  • Pipeline finished with Success
    about 1 year ago
    Total: 502s
    #70682
  • πŸ‡«πŸ‡·France andypost

    Not sure it makes sense to have this sessions in .htaccess and setting.php as well

    I'd just removed this lines

  • πŸ‡ΊπŸ‡ΈUnited States darren oh Lakeland, Florida

    settings.local.php has a different value for development environments.

  • Status changed to Needs work 11 months ago
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    Left a comment on the MR

  • πŸ‡ΊπŸ‡ΈUnited States darren oh Lakeland, Florida

    We should just replace the deprecated setting with the correct setting and stop trying to remove something that helps users set up a development environment correctly. Recommending a correct setting for php.ini is compatible with showing how to override it temporarily in the example settings.local.php.

  • πŸ‡·πŸ‡ΊRussia Chi

    assert.active takes precedence over zend.assertions. Does it mean all tests running on Apache does not check for assertions? If so I would consider this as a bug.

  • Status changed to Needs review 10 months ago
  • πŸ‡ΊπŸ‡ΈUnited States darren oh Lakeland, Florida

    Chi, we have always disabled checking for assertions in Apache by default, with the option to enable checking in settings.local.php. Please review.

  • πŸ‡ΊπŸ‡ΈUnited States darren oh Lakeland, Florida
  • πŸ‡ΊπŸ‡ΈUnited States darren oh Lakeland, Florida
  • πŸ‡ΊπŸ‡ΈUnited States darren oh Lakeland, Florida
  • πŸ‡·πŸ‡ΊRussia Chi

    If zend_assertions is set to prod mode, in php.ini this statement in .htaccess

    + php_value zend.assertions 0

    causes the following warning in Apache error log

    [php:warn] [pid 176] [client 172.29.0.254:50836] PHP Warning: zend.assertions may be completely enabled or disabled only in php.ini in Unknown on line

  • πŸ‡ΊπŸ‡ΈUnited States darren oh Lakeland, Florida

    The default value is 1, so if an administrator sets it to -1 they can also remove the line from .htaccess.

  • πŸ‡·πŸ‡ΊRussia Chi

    The default value is 1

    The default value may be set by Linux distributions or hosting providers. They don't know much about Drupal requirements.

  • πŸ‡ΊπŸ‡ΈUnited States mfb San Francisco

    The recommended php config for production has zend.assertions at -1, and I think this will be pretty commonly installed. And so you have that warning message logged for every request. My 2 cents is that setting zend.assertions is something that should be documented for developers to do, rather than happening out-of-the-box

  • Pipeline finished with Failed
    10 months ago
    Total: 170s
    #126471
  • Pipeline finished with Success
    10 months ago
    Total: 616s
    #126475
  • Status changed to RTBC 7 months ago
  • πŸ‡«πŸ‡·France andypost

    Looks ready to go, comments make sense, thank you!

  • Status changed to Needs work 7 months ago
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    I think the change record needs updating. We're no longer setting in .htaccess and we appear to be recommending managing this in your php.ini. The Cr should explain the intricacies here.

  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    Analysis: assertions enabled until you update to the latest example.settings.local.phpπŸ‘»

    This caused hours of wasted time, due to assertions no longer being enabled automatically if you opt in to using settings.local.php.

    1. #3186524: Fix htaccess files for PHP 8 β†’ added
      <IfModule mod_php.c>
        php_value assert.active                   0
      </IfModule>
      

      which worked fine in tandem with example.settings.local.php at the time

    2. but then πŸ“Œ Fix deprecated assert_options() function usage for PHP 8.3 Needs review reverted the assertion-enabling logic in example.settings.local.php, because it used the PHP 8.3+ deprecated assert.active, without changing the .htaccess to match
    3. #3375693's CR ( https://www.drupal.org/node/3391611 β†’ ) tells you to enable assertions by manually adding ini_set('zend.assertions', 1); to settings.local.php (requiring to do this manually is a DX regression FWIW) … BUT THIS DOES NOT WORK due to the assert.active=0 in the .htaccess πŸ€ͺπŸ™ˆ It has no effect, because while assert.active is deprecated, it does have an effect! IOW: the CR is broken.

    This required over an hour of falling down the rabbit hole, culminating in #3500110-5: PHP asserts not running in CI/during tests β†’ , and caused a significant disruption to Experience Builder.

    I did not notice this for a long time because I had carried over my own settings.local.php until very recently … πŸ‘» … because while PHP 8.3 might have deprecated using assert_options(…), it totally worked fine!

    Manual test: πŸ‘

    I manually tested this MR and can confirm this restores the original, expected DX: enabling settings.local.php.

    … and AFAICT

    πŸ“Œ Fix deprecated assert_options() function usage for PHP 8.3 Needs review also removed this from DrupalKernel:

            // Web tests are to be conducted with runtime assertions active.
            assert_options(ASSERT_ACTIVE, TRUE);
            // Force assertion failures to be thrown as exceptions.
            assert_options(ASSERT_EXCEPTION, TRUE);
    

    … does that mean that currently GitLab CI is running the test suite without assertions enabled too? https://git.drupalcode.org/project/gitlab_templates has zero matches for the keyword "assert" 😱 I'm afraid that's the case…

  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    RE: AFAICT in #31: I can now confirm that

    <IfModule mod_php.c>
      php_value assert.active                   0
    </IfModule>
    

    disables assertions during tests in a way that cannot actually be restored by the recommended settings.local.php when running tests locally using Apache as the web server! You actually need to bring back assert.active πŸ˜…

    This is not a problem when developing or testing Drupal in a non-Apache web server, because .htaccess has no effect on those.

    Potential work-arounds:

    1. Add a </code> to the <code>.module file of your contrib module for whose test runs you want to enable assertions (thanks @longwave!) β€” see #3500110-10: PHP asserts not running in CI/during tests β†’
    2. Append this to .htaccess:
      <IfModule mod_php.c>
        php_value zend.assertions                   1
        # Revert this part when https://www.drupal.org/project/drupal/issues/3398033 is fixed in Drupal core.
        php_value assert.active                   1
      </IfModule>
      

      (should be doable in .gitlab-ci.yml, too)

  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    Should we add

    if (ini_get('zend.assertions') !== -1) {
      ini_set('zend.assertions', 1);
    }
    

    and even though it's deprecated maybe even

    ini_set('assert.active', 1);
    

    back to DrupalKernel::bootEnvironment() when we detect we are running in a test environment? This would attempt to force a more consistent environment in tests.

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    This lead me to finding πŸ› \Drupal\Tests\system\Kernel\MenuAccessControlHandlerTest::testAccessProvider Active for trivial patch of the month.

  • πŸ‡«πŸ‡·France andypost

    ini_set('zend.assertions', 1);ini_set('zend.assertions', 1);

    This settings can be changed only starting PHP https://www.php.net/manual/en/ini.core.php#ini.zend.assertions

  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    @andypost I read that as: if it's -1 you cannot change it, but otherwise you can swap between 0 and 1 at runtime?

  • πŸ‡·πŸ‡ΊRussia Chi

    Re #36. That's correct. And if we should probably emit some notice when assertions are in production mode when running tests.

Production build 0.71.5 2024