Remove all calls to assert_options() conforming to PHP 7 spec, and adjust all runtime assertion related unit tests to skip on assert off.

Created on 16 October 2017, over 6 years ago
Updated 30 January 2023, over 1 year ago

Problem/Motivation

PHP default assertion handling has been changed in 7. The time has arrived to move to a PHP 7 conformant setup.

Proposed resolution

First we must remove calls to the assert_options() function. This allows for runtime manipulation of assertion activity, and we have unit tests that manipulate it as well as the PHP 5/7 compat shim in the Assertion\Handle library. These need to go. Relevant from the PHP docs:

While assert_options() can still be used to control behaviour as described above for backward compatibility reasons, PHP 7 only code should use the two new configuration directives to control the behaviour of assert() and not call assert_options().

I read this with a strong possibility that assert_options() might find itself deprecated and removed at some point in the future.

Since the .htaccess file does not affect the PHPUnit tests ran from the command line it becomes incumbent on the environment files to set this functionality up correctly. References to assertions will be removed from .htaccess as they set up a false expectation that this file alone can control them.

assert.exception

This flag determines whether exceptions are thrown on assert failure (1) or if a warning is emitted (0). The default is 0, errors, and this is the PHP 5 compatible behavior. The PHP default is 0, and Drupal should have this setting set to 1.

zend.assertions

There are three possible values as detailed in the PHP docs. They are:

  • 1: generate and execute code (development mode)
  • 0: generate code but jump around it at runtime
  • -1: do not generate code (production mode)

1 is the default. 0 is an emulation of PHP 5 behavior for backwards compatibility and shouldn't be considered as a possible candidate. -1 should be the production default.

Performance Concerns

Since PHP ships with assertions on by default leaving it to the site admins to turn them off will incur a performance hit for those who fail to do so. If we are to follow the PHP Group recommendation though we have no choice. Also, there are advantages to this approach - we can run the tests with runtime assertions turned on or off at our leisure so long as all unit tests which check to see if an assertion was tripped are skipped when assertions are turned off.

Whither PHP 5?

Once the parent ticket to this one is implemented PHP 5 will always run assertion related code, it just won't check to see if the return was true or false. So if there's a site breaking bug in that code under PHP 5 it will be found when the test fails to run because of the bug. In effect we are taking advantage of PHP 5's bad design of running assertions at all times.

Remaining tasks

Resolve: πŸ“Œ Improve assertion test failures with bad zend.assertions value Needs work
None for this ticket. There is a child issue ticket for the status report change.

User interface changes

The status report will include zend.assertions current setting and mark it as a potential problem if it isn't the production value of -1.

API changes

None.

Data model changes

None.

πŸ“Œ Task
Status

Needs work

Version

10.1 ✨

Component
BaseΒ  β†’

Last updated 1 minute ago

Created by

πŸ‡ΊπŸ‡ΈUnited States Aki Tendo

Live updates comments and jobs are added and updated live.
  • Runtime assertion

    It deals with the addition of an assert() statement(s) to the code, and/or contains a test patch where one is failing indicating a need to change code or the documentation the statement was based on.

  • Performance

    It affects performance. It is often combined with the Needs profiling tag.

  • needs profiling

    It may affect performance, and thus requires in-depth technical reviews and profiling.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • The Needs Review Queue Bot β†’ tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

Production build 0.69.0 2024