Problem/Motivation

From the PHP manual:

By default, PHP will coerce values of the wrong type into the expected scalar type declaration if possible. For example, a function that is given an int for a parameter that expects a string will get a variable of type string.

This silent type-casting is often unintentional and can result in bugs.

If we set declare(strict_types=1); at the top of a file, then "only a value corresponding exactly to the type declaration will be accepted, otherwise a TypeError will be thrown. The only exception to this rule is that an int value will pass a float type declaration."

Proposed resolution

Set declare(strict_types=1); in the module files that we don't get do that. Review variable usage in those files before committing. Make sure tests still pass afterwards.

As of commit c3f1e98 from 2026-05-06, there are 21 PHP files in this module that we do not declare strict types in (using ripgrep, rg -g '*.php' --files-without-match -i -F -e 'declare(strict_types=1);' will find the list of files.

Remaining tasks

  1. Merge request - merge request !16 created by @mparker17 in #2
  2. Community/Maintainer review - skipped by @mparker17 in #3
  3. Commit - merged by @mparker17 in #4
  4. Release

User interface changes

None.

API changes

None.

Data model changes

None.

Issue fork feedback-3588845

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

mparker17 created an issue. See original summary.

mparker17’s picture

Issue summary: View changes
Status: Active » Reviewed & tested by the community

Created merge request !16. Skipping community/maintainer review because this was written by a maintainer. Merging shortly.

  • mparker17 committed 4242aac5 on 3.x
    feat: #3588845 Declare strict_types in all PHP files
    
    By: mparker17
    
mparker17’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Fixed

Merged. I will update this when it gets released.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.