Skip to content

Fix: Add default values to GoalSettings for PHP 8.1+ compatibility #8002

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

pauloiankoski
Copy link
Contributor

@pauloiankoski pauloiankoski commented Jul 2, 2025

Resolves https://lw.slack.com/archives/C072VS4FT1A/p1750798143514369

Description

This PR fixes fatal errors that occur in PHP 8.1+ when using the GoalSettings class. The issue occurs when any of the expected keys are missing or null in the data array passed to the fromArray() method, because the strict types declared in the class will trigger a fatal error if invalid values are passed in.

Root Cause: PHP 8.1+ enforces stricter type checking, and when properties with strict type declarations receive null or undefined values, it causes fatal errors.

Solution: Added default values using the null coalescing operator to ensure all properties receive appropriate fallback values:

  • goalSource: defaults to empty string
  • enableDonationGoal: defaults to false
  • goalType: defaults to GoalType::AMOUNT
  • goalAmount: defaults to 0

Affects

Goal Settings

Visuals

N/A - This is a backend compatibility fix with no visual interface changes.

Testing Instructions

  1. PHP 8.1+ Environment: Test on PHP 8.1 or higher
  2. Create GoalSettings with incomplete data to verify no fatal errors occur
  3. Test donation form creation with missing goal settings data
  4. Verify default values are properly applied when data is missing
  5. Test with complete data to ensure normal functionality still works

Pre-review Checklist

  • Acceptance criteria satisfied and marked in related issue
  • Relevant @unreleased tags included in DocBlocks
  • Includes unit tests
  • Reviewed by the designer (if follows a design) - N/A
  • Self Review of code and UX completed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants