Skip to content
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

[2.0] Use null instead of false on failure #190

Open
enumag opened this issue Apr 10, 2019 · 6 comments
Open

[2.0] Use null instead of false on failure #190

enumag opened this issue Apr 10, 2019 · 6 comments

Comments

@enumag
Copy link
Contributor

enumag commented Apr 10, 2019

I noticed that some methods of Collection return false on failure. Specifically first(), last(), current(), next() and indexOf(). It would be better in my opinion to return null instead.

Since this is a BC break I'd like to propose this for doctrine/collections 2.0.

c3564a6
(Of course all Collection implementations and tests would need to be changed accordingly.)

@ThomasLandauer
Copy link
Contributor

Returning null would allow using PHP 8.0's nullsafe operator: $foo->getBars()->first()?->getName();

@jeromegxj
Copy link

What is the status of this issue? I'm willing to implement it if needed.
Personally I'll be more than happy to have it, we may want to have methods like: ->firstOrNull() to keep BC?
Let me know

@derrabus
Copy link
Member

I'm not aware that anyone is working on this issue, so feel free to do so.

@jeromegxj
Copy link

A try has been given leading to a discussion
The conclusion is that this is too much of a breaking change to be done even if it would go to the next major version.

@mbolli
Copy link

mbolli commented Apr 26, 2024

Maybe a year later we could revisit this issue, or does the team still have the same opinion?

This is one of my only gripes with Doctrine, always having to use
$obj->getRelation()->isEmpty() ? null : $obj->getRelation()->first()->getField();
instead of the much better readable
$obj->getRelation()->first()?->getField()

@derrabus
Copy link
Member

Maybe a year later we could revisit this issue, or does the team still have the same opinion?

My opinion hasn't changed: #362 (comment)

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

No branches or pull requests

6 participants