Skip to content

[12.x] Use MissingValue as default to distinguish between omitted and explicit null #56394

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

Merged
merged 1 commit into from
Jul 24, 2025

Conversation

Edvarde
Copy link
Contributor

@Edvarde Edvarde commented Jul 24, 2025

Replace null defaults with MissingValue to make behavior more explicit and IDE-friendly

Problem

When using helper methods like:

->when($condition, $value, null)

many IDEs (e.g., PhpStorm) suggest that the third argument is redundant because it matches the default (null).
If a developer removes it (trusting the IDE), the behavior changes silently:

  • ->when(..., null) → the field is included in the response with value null
  • ->when(...) → the field is skipped entirely (because MissingValue is used internally)
    This leads to non-obvious bugs, especially when the difference between null and "not passed at all" is significant.

Solution

This PR changes the default value from null to new MissingValue in affected helper methods.

Why this matters:

  • Makes the distinction between null and "not provided" explicit
  • Prevents IDEs from suggesting misleading simplifications
  • Improves developer experience and reduces potential bugs
  • Encourages conscious handling of optional parameters

After this change, the difference is clearly reflected in the method signature. IDEs will no longer suggest removing null without warning.

@Edvarde Edvarde changed the title Use MissingValue as default to distinguish between omitted and explicit null [12.x] Use MissingValue as default to distinguish between omitted and explicit null Jul 24, 2025
@taylorotwell taylorotwell merged commit 2c346ce into laravel:12.x Jul 24, 2025
62 checks passed
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.

3 participants