Skip to content

Conversation

@cosmastech
Copy link
Contributor

@cosmastech cosmastech commented Dec 5, 2025

Saying goodbye to a relic from a bygone era.

We will always remember the good times we shared with optional(), the laughs and the tears. Listening to tunes on our iPods, drinking Four Lokos, and reaching for values which may or may not exist on a mixed type variable.

@bert-w
Copy link
Contributor

bert-w commented Dec 6, 2025

Any plans to @deprecated the original optional() function? I myself have never used it and always preferred language constructs.

@shaedrich
Copy link
Contributor

Well, after all, if people still want to use it, no harm in that

@taylorotwell taylorotwell merged commit ed061e2 into laravel:12.x Dec 6, 2025
74 checks passed
@jasonmccreary
Copy link
Contributor

While I can't remember off the top of my head, years of Shift support lead me to believe there is a boundary case which optional covers that the nullsafe does not. Not speaking to this PR specifically, just generally commentary.

@cosmastech cosmastech deleted the remove-optional branch December 9, 2025 19:29
@rodrigopedra
Copy link
Contributor

@jasonmccreary

I didn't use optional() for years.

Sometime ago, assessing an older codebase, I asked the developer why he kept using it, and he told me this:

  • The underlying Optional class is macroable. So for lots of the DB façade calls without models, he could "add" methods to the \stdClass results:

    Optional::macro('toArray', fn() => (array) $this->value);
    
    \dump(\optional(\literal(name: 'Rodrigo'))->toArray());
  • And, for some reason, he also often used the second $callback argument, as it only applies the callback when the value is not null

Might have to do with those cases.

I imagine it would be difficult to identify the first case in an automated code migration (calling a macro that might not have been defined in an obvious spot).

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.

6 participants