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

[5.4] Cast ids to array #20330

Merged
merged 3 commits into from
Jul 31, 2017
Merged

[5.4] Cast ids to array #20330

merged 3 commits into from
Jul 31, 2017

Conversation

fernandobandeira
Copy link
Contributor

@fernandobandeira fernandobandeira commented Jul 30, 2017

This PR fixes another call to count that is throwing an exception on PHP7.2

@fernandobandeira fernandobandeira changed the title ]5.4Cast ids to array [5.4] Cast ids to array Jul 30, 2017
@@ -349,7 +349,7 @@ public function detach($ids = null, $touch = true)
// associations, otherwise all of the association ties will be broken.
// We'll return the numbers of affected rows when we do the deletes.
if (! is_null($ids = $this->parseIds($ids))) {
if (count($ids) === 0) {
if (count((array) $ids) === 0) {
Copy link
Contributor

@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.

I'm confused. Why does the null check prior to this line not stop us getting here in the first place?

If it's not null - then it should be a countable result?

Copy link
Contributor

@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.

Actually - this is not an error here. It's in ParseIds() - since it should always return an array?

Copy link
Contributor Author

@fernandobandeira fernandobandeira Jul 31, 2017

Choose a reason for hiding this comment

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

It's failing on master, check failed test 23) https://travis-ci.org/laravel/framework/jobs/259204796 https://github.com/laravel/framework/blob/master/tests/Integration/Database/EloquentBelongsToManyTest.php#L179 is passing an integer to the function, integer also isn't considered a countable result.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep - see my comment below. IMO it should be fixed in a different way.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, it makes no sense that we would even hit this line with null?

Copy link
Contributor

@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.

@taylorotwell - we worked it out. The parseIds() function returns mixed, not array().

So you can end up with count(1) if it was just a single model id - which will now fail in PHP7.2, because 1 (the int) is not countable.

@laurencei
Copy link
Contributor

laurencei commented Jul 31, 2017

edit: disregard - now fixed.

@fernandobandeira
Copy link
Contributor Author

fernandobandeira commented Jul 31, 2017

Actually that's the correct fix, changing parseIds will make it not pass the if clause anymore (it'll never be a null value), I've changed the docblock then.

@taylorotwell taylorotwell merged commit 677b05a into laravel:5.4 Jul 31, 2017
taylorotwell pushed a commit that referenced this pull request Jul 31, 2017
* Fix travis CI error

* Cast ids to array

* Revert cast in favor of #20330

* Always remove xdebug
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