Skip to content

Prepare for PHP 8.5 and PHP 9.0: NullToStrictStringFuncCallArgRector#5575

Open
dcsjulio wants to merge 2 commits intoe107inc:masterfrom
dcsjulio:master
Open

Prepare for PHP 8.5 and PHP 9.0: NullToStrictStringFuncCallArgRector#5575
dcsjulio wants to merge 2 commits intoe107inc:masterfrom
dcsjulio:master

Conversation

@dcsjulio
Copy link
Copy Markdown
Contributor

@dcsjulio dcsjulio commented Feb 23, 2026

Rule: NullToStrictStringFuncCallArgRector (https://getrector.com/rule-detail/null-to-strict-string-func-call-arg-rector)

In versions of PHP prior to 8.1, passing null to native functions that expected a string (such as strlen(), explode(), trim(), or str_replace()) would trigger an internal "coercion." PHP would silently convert the null value into an empty string (""), allowing the execution to continue without warnings.

As of PHP 8.1, this behavior was deprecated, and in PHP 8.4 and 8.5, the engine has moved towards strict type enforcement. This Rector rule explicitly adds a (string) cast to arguments passed to these native functions whenever the variable could potentially be null.

Motivation and Context

Being able to use e107 with php8.5 and future releases. Avoid potential flaws.

Description

Cast to string (null ==> '') for arguments where non null values are expected.

Used php rector for the changes, just the rule: NullToStrictStringFuncCallArgRector

Also: Some identation is changed because of the tool: empty lines will remove trailing spaces.

How Has This Been Tested?

Running the tests

Types of Changes

  • Bug fix (non-breaking change which fixes a FUTURE issue)
  • New feature (non-breaking change which adds functionality)
  • Performance enhancement (non-breaking change which improves efficiency)
  • Code cleanup (non-breaking change which makes code smaller or more readable)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (a change to man pages or other documentation)

Checklist

de Castro Sanchez, Julio Ezequiel added 2 commits February 23, 2026 19:26
Rule: NullToStrictStringFuncCallArgRector (https://getrector.com/rule-detail/null-to-strict-string-func-call-arg-rector)

In versions of PHP prior to 8.1, passing null to native functions that expected a string (such as strlen(), explode(), trim(), or str_replace()) would trigger an internal "coercion." PHP would silently convert the null value into an empty string (""), allowing the execution to continue without warnings.

As of PHP 8.1, this behavior was deprecated, and in PHP 8.4 and 8.5, the engine has moved towards strict type enforcement. This Rector rule explicitly adds a (string) cast to arguments passed to these native functions whenever the variable could potentially be null.
@dcsjulio
Copy link
Copy Markdown
Contributor Author

Hi,

I am working on preparing the codebase to fully support PHP 8.5 and future releases.

To achieve this, I am cherry-picking specific Rector rules. The first one is NullToStrictStringFuncCallArgRector, which is critical for modern PHP versions.

Rector analyzes whether variables might contain null values. In cases of type ambiguity (common with database-stored data or legacy code), it adds an explicit (string) cast when passing those variables to core functions. This prevents TypeErrors and silences deprecation warnings that are becoming stricter in PHP 8.5 and will be fatal in PHP 9.0.

It may be a good idea to accept these automated corrections now to ensure stability. As the codebase evolves and we implement more strict type hinting across the project, we can review these casts on a case-by-case basis and remove those that are no longer necessary.

Regarding the CI, the Acceptance tests failed with an SFTP deployment error. I am unsure if this is related to my changes or a pre-existing infrastructure issue. Could you please take a look?

Thank you!

@dcsjulio dcsjulio marked this pull request as ready for review February 24, 2026 07:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant