Skip to content

Fix deprecated null passed to str_replace in get_field_value_for_new_entry - #3332

Closed
wzul wants to merge 1 commit into
Strategy11:masterfrom
wzul:fix/null-default-value-deprecation
Closed

wzul wants to merge 1 commit into
Strategy11:masterfrom
wzul:fix/null-default-value-deprecation

Conversation

@wzul

@wzul wzul commented Sep 12, 2026 •

Copy link
Copy Markdown

What this fixes

FrmEntriesHelper::get_field_value_for_new_entry() passes a possibly-null value to str_replace(), which emits a deprecation notice on PHP 8.1+:

Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
in /wp-content/plugins/formidable/classes/helpers/FrmEntriesHelper.php on line 132

$new_value starts as $field->default_value, which is null for a field that has no default value. It stays null when the field's value is not posted back either, and the ! is_array() branch then hands that null straight to str_replace().

It shows up on the front end of any form containing such a field whenever WP_DEBUG_DISPLAY is on.

The change

+		// A field with no default value has a null default_value, and a field type
+		// whose value is not posted back leaves it null too. str_replace() warns on
+		// a null subject in PHP 8.1+, so cast first: this keeps returning the empty
+		// string the caller already relied on.
 		if ( ! is_array( $new_value ) ) {
-			return str_replace( '"', '"', $new_value );
+			return str_replace( '"', '"', (string) $new_value );
 		}

The cast rather than an early return $new_value is deliberate: the caller assigns the result to $field_array['value'], and PHP already coerced null to '' here, so casting preserves the existing behaviour exactly instead of introducing null where callers expect a string.

Verification

Checked with error_reporting( E_ALL ) that the new expression returns the identical value to the old one for every input that reaches this branch:

Input Before After Same
null (no default value) '' + deprecation '' yes
'' '' '' yes
'Hello' 'Hello' 'Hello' yes
'He said "hi"' 'He said "hi"' 'He said "hi"' yes
0 '0' '0' yes
'0' '0' '0' yes

Reported from a WordPress 7.1 / PHP 8.3 environment with Formidable 6.35; the same line is present on master today.

Summary by CodeRabbit

  • Bug Fixes
    • Prevented PHP 8.1+ warnings when creating new entries with empty or non-array field values.
    • Preserved existing empty-string behavior for affected fields.

…r_new_entry

A field without a default value has a null default_value, and a field type whose
value is not posted back leaves it null as well. Passing that null to
str_replace() as the subject is deprecated in PHP 8.1+ and logs:

  Deprecated: str_replace(): Passing null to parameter Strategy11#3 ($subject) of type
  array|string is deprecated in classes/helpers/FrmEntriesHelper.php on line 132

It is visible on any form that has such a field while WP_DEBUG_DISPLAY is on.

Casting before the call keeps the empty string the caller already received, so
no behaviour changes: the same value is returned for null, an empty string, a
plain string, and a string containing a quote.
@coderabbitai

coderabbitai Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 0d85625a-a677-487a-83ac-ab6fa3319648

📥 Commits

Reviewing files that changed from the base of the PR and between 5d01123 and 9b7a223.

📒 Files selected for processing (1)
  • classes/helpers/FrmEntriesHelper.php

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The entry helper now casts non-array field values to strings before escaping quotes. Null values continue to produce an empty string without PHP 8.1+ warnings.

Changes

Entry value handling

Layer / File(s) Summary
Null-safe field value escaping
classes/helpers/FrmEntriesHelper.php
Non-array field values are cast to strings before str_replace(). Null values produce an empty string without warnings.

Priority: ⬇️ Low

Estimated code review effort: 1 (Trivial) | ~5 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: crabcyborg

Merge Risk: ⚪ Minimal · up to 9b7a2

The cast removes the PHP deprecation while preserving the intended empty-string and quote-escaping behavior.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: preventing a deprecated null value from being passed to str_replace() in get_field_value_for_new_entry().
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@deepsource-io

deepsource-io Bot commented Sep 12, 2026 •

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in 5d01123...9b7a223 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
PHP Sep 12, 2026 3:58p.m. Review ↗
JavaScript Sep 12, 2026 3:58p.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

@Crabcyborg Crabcyborg added this to the 6.36 milestone Sep 28, 2026
@Crabcyborg Crabcyborg removed this from the 7.0 milestone Oct 13, 2026
@Crabcyborg

Copy link
Copy Markdown
Contributor

Thank you @wzul for your PR.

We tend to solve this sort of issue slightly differently, by checking earlier rather than converting the null to an empty string and then passing it through str_replace.

So I made a new PR to replace this #3570

This will go into this week's v7.0 release.

Closing.

@Crabcyborg Crabcyborg closed this Oct 13, 2026
@wzul
wzul deleted the fix/null-default-value-deprecation branch October 14, 2026 02:28
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.

2 participants