PHP Fatal Error in GF Survey Add-On — array_search() null argument in class-gf-survey.php (is_value_match_rank)

We’re experiencing a recurring PHP fatal error in the Gravity Forms Survey Add-On (v4.2.1) on PHP 8.4, WordPress 7.0.4, Gravity Forms 3.0.2, hosted on WP Engine.

Error:

PHP Fatal error: Uncaught TypeError: array_search(): Argument #2 ($haystack) must be of type array, null given in class-gf-survey.php

Location: class-gf-survey.php, method is_value_match_rank(), line 920:

php

$choice_value_index = array_search( $choice_value, $source_field->choices[$field_index] );

Root cause: $source_field->choices[$field_index] can be null when the array key doesn’t exist (preceded by “Undefined array key” notices). PHP 8.x enforces the array type requirement on array_search(), causing a fatal error that crashes survey submissions.

Our workaround:

php

$choice_value_index = is_array( $source_field->choices[$field_index] ) ? array_search( $choice_value, $source_field->choices[$field_index] ) : false;

This fix works, but it gets overwritten every time the plugin updates. We’ve had to reapply it three times now. This is impacting an active survey used by 40,000+ union members during contract negotiations.

Could this is_array() guard be added to the plugin source in a future release?

Try updating to version 4.2.3, which was released late yesterday.

If you still have issues after updating, please open a support ticket at: https://www.gravityforms.com/open-support-ticket/technical/