Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion classes/helpers/FrmAppHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3032,7 +3032,7 @@ private static function fill_form_defaults( $post_values, array &$values ) {
foreach ( $form_defaults as $opt => $default ) {
// phpcs:ignore Universal.Operators.StrictComparisons
if ( ! isset( $values[ $opt ] ) || $values[ $opt ] == '' ) {
$values[ $opt ] = $post_values && isset( $post_values['options'][ $opt ] ) ? $post_values['options'][ $opt ] : $default;
$values[ $opt ] = $post_values['options'][ $opt ] ?? $default;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# First, let's look at the function context around line 3035
sed -n '3029,3051p' classes/helpers/FrmAppHelper.php

Repository: Strategy11/formidable-forms

Length of output: 855


🏁 Script executed:

# Search for all calls to fill_form_defaults
rg 'fill_form_defaults' --type php -B 2 -A 2

Repository: Strategy11/formidable-forms

Length of output: 621


🏁 Script executed:

# Check for any validation of $post_values before the problematic line
sed -n '3000,3040p' classes/helpers/FrmAppHelper.php

Repository: Strategy11/formidable-forms

Length of output: 1124


🏁 Script executed:

# Find the function that contains the fill_form_defaults call
grep -n 'fill_form_defaults' classes/helpers/FrmAppHelper.php

Repository: Strategy11/formidable-forms

Length of output: 211


🏁 Script executed:

# Get context around the call - look at lines before 3018
sed -n '2950,3025p' classes/helpers/FrmAppHelper.php

Repository: Strategy11/formidable-forms

Length of output: 1950


🏁 Script executed:

# Find all calls to fill_form_opts
rg 'fill_form_opts' --type php -B 3 -A 3

Repository: Strategy11/formidable-forms

Length of output: 1046


🏁 Script executed:

# Also search for where $post_values is created/prepared
rg 'post_values\s*=' --type php -B 2 -A 2 | head -100

Repository: Strategy11/formidable-forms

Length of output: 2045


🏁 Script executed:

# Find where post_values is populated with 'options' key
rg "post_values\['options'\]" --type php -B 2 -A 2 | head -80

Repository: Strategy11/formidable-forms

Length of output: 1655


🏁 Script executed:

# Check the function signature and default value of $post_values
sed -n '2840,2860p' classes/helpers/FrmAppHelper.php

Repository: Strategy11/formidable-forms

Length of output: 620


🏁 Script executed:

# Look for any code that explicitly sets $post_values['options']
rg "post_values\s*\[\s*['\"]options['\"]" --type php -B 1 -A 1

Repository: Strategy11/formidable-forms

Length of output: 1241


This change introduces a defensive coding inconsistency.

The null coalescing operator at line 3035 ($post_values['options'][$opt] ?? $default) lacks the defensive checks used elsewhere in the codebase for the same operation. In the same file, custom_style_value() uses $post_values && isset( $post_values['options']['custom_style'] ), and FrmFormsHelper.php uses $post_values && isset( $post_values['options'][ $var ] ) for identical nested array access patterns.

If $post_values is falsy or the 'options' key is missing, this could produce PHP notices in versions prior to PHP 8. Consider adding a defensive check to match the established pattern in the codebase:

$values[ $opt ] = ( $post_values && isset( $post_values['options'][ $opt ] ) ) ? $post_values['options'][ $opt ] : $default;
🤖 Prompt for AI Agents
In @classes/helpers/FrmAppHelper.php at line 3035, Replace the null-coalescing
access used to populate $values[$opt] with the same defensive pattern used
elsewhere: check that $post_values is truthy and that the nested 'options' key
for $opt is set before using it, otherwise fall back to $default; mirror the
approach used in custom_style_value() and FrmFormsHelper.php for $post_values &&
isset($post_values['options'][$var]) to avoid PHP notices.

}

unset( $opt, $default );
Expand Down
Loading