Skip to content

[5.4] Refactor pivot fix for PHP7.2#20336

Merged
taylorotwell merged 2 commits into
laravel:5.4from
laurencei:pivotfix
Jul 31, 2017
Merged

[5.4] Refactor pivot fix for PHP7.2#20336
taylorotwell merged 2 commits into
laravel:5.4from
laurencei:pivotfix

Conversation

@laurencei
Copy link
Copy Markdown
Contributor

@laurencei laurencei commented Jul 31, 2017

I think it makes more sense to keep parseIds() as an array return (as it was 15mins ago before #20330) - and instead just remove all the casting that was occuring throughout the function.

i.e. every time parseIds() was called - it was being cast to array - so we might as well just honor the original docblock intention and fix the bug in parseIds() itself.

This also solves the count() issue for PHP7.2, so that you only ever count an array, and still honors the null returns for $ids if that situation occurs.

All tests pass green pre/post this change.

if (! is_null($ids = $this->parseIds($ids))) {
if (count((array) $ids) === 0) {
if (! is_null($ids)) {
$ids = $this->parseIds($ids);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 The only change of behavior here is for the case where you'd pass a Model instance that isn't saved yet (thus id = null).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm... let me check.

What would a failing test for that look like? Would be good to capture it...

Copy link
Copy Markdown
Contributor Author

@laurencei laurencei Jul 31, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that because your saying inside parseIds() that $value->getKey() might return null itself?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about use empty instead of count? Need to test if not gonna break

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gmsantos - nice idea - that would work.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@laurencei Yep that's exactly it however IMO that seems more like a bug than a feature so the change shouldn't matter... 😄

@taylorotwell taylorotwell merged commit 22db4f6 into laravel:5.4 Jul 31, 2017
@laurencei laurencei deleted the pivotfix branch July 31, 2017 15:15
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.

4 participants