Fatal error when changing membership type, on membership with 0 contributions
Steps to reproduce
- Create a membership without a contribution.
- Edit the membership you just created, change the membership type, and save (again without a contribution)
Expected result
The membership should correctly save both times.
Expected result
The second save does not save correctly/ causes a 500 server error.
The error message is:
Fatal error: Uncaught Error: max(): Argument #1 ($value) must contain at least one element
in /app/web/app/plugins/civicrm/civicrm/CRM/Member/Form/Membership.php on line 1547
Call stack:
1. max()
app/plugins/civicrm/civicrm/CRM/Member/Form/Membership.php:1547
2. CRM_Member_Form_Membership::setStatusMessage()
app/plugins/civicrm/civicrm/CRM/Member/Form/Membership.php:1380
3. CRM_Member_Form_Membership::submit()
app/plugins/civicrm/civicrm/CRM/Member/Form/Membership.php:881
4. CRM_Member_Form_Membership::postProcess()
app/plugins/civicrm/civicrm/CRM/Core/Form.php:573
...
The membership does appear to actually be saved correctly upon refreshing the page.
Environment information
PHP 8.1
I cannot reproduce this on dmaster. I think this is because calling max(array_keys([]))
on PHP 7.4 merely causes a warning, whereas on PHP 8.x it causes an Uncaught ValueError
.