| @@ -280,8 +280,19 @@ | ||
| 280 | 280 | */ |
| 281 | 281 | public function add_donation( $campaign_id, $amount, $period = 'once' ) { |
| 282 | 282 | $donations = $this->get( 'donations' ); |
| 283 | 283 | |
| 284 | + /* | |
| 285 | + * get() returns false when the key is not in the session, which is the normal state for the | |
| 286 | + * first donation of a fresh session. Assigning $donations[ $campaign_id ] to that false | |
| 287 | + * relied on PHP silently converting it to an array - deprecated in PHP 8.1 and a fatal | |
| 288 | + * TypeError in PHP 9, on the donation path. add_donation_key() below already guards exactly | |
| 289 | + * this way; this method was simply missing it. | |
| 290 | + */ | |
| 291 | + if ( ! is_array( $donations ) ) { | |
| 292 | + $donations = array(); | |
| 293 | + } | |
| 294 | + | |
| 284 | 295 | $campaign_donation = isset( $donations[ $campaign_id ] ) ? $donations[ $campaign_id ] : array(); |
| 285 | 296 | $campaign_donation['amount'] = floatval( charitable_get_currency_helper()->cast_to_decimal_format( $amount ) ); |
| 286 | 297 | $campaign_donation['donation_period'] = $period; |
| 287 | 298 | |