elisseck / com.elisseck.civihoneypot

Simple honeypot fields for CiviCRM Contribute forms
Other
3 stars 6 forks source link

PHP8.0 Fix type error passing in NULL when it expects an array #19

Closed seamuslee001 closed 1 year ago

seamuslee001 commented 1 year ago

This fixes a type error on a clients site running PHP8.0 the issue is that if you leave the say honeypot_form_ids settings black Civi::settings() will supply the default which is null and there for an array_key_exists and CRM_Utils_Array::value will supply the setting default value of NULL instead of []

This uses the ?? operator to ensure an array is passed through

Example settings array that was causing the issue var_dumped out

array(7) { ["honeypot_form_ids"]=> NULL ["honeypot_protect_all"]=> NULL ["honeypot_field_names"]=> array(1) { [0]=> string(3) "url" } ["honeypot_limit"]=> NULL ["honeypot_ipban"]=> NULL ["honeypot_event_ids"]=> NULL ["honeypot_protect_all_events"]=> string(1) "1" }
monishdeb commented 1 year ago

I have tested on my local setup and agree with the fixes made. @elisseck can you please take look at this patch?

elisseck commented 1 year ago

Thanks! Sorry I haven't seen these. My assumption was that everyone has moved to using https://lab.civicrm.org/extensions/formprotection where matt included most of the relevant code from this extension plus new features.