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.2.40] Pagination broken on PHP7.0.8 (Division by 0) #14387

Closed
alexhouse opened this issue Jul 20, 2016 · 6 comments
Closed

[5.2.40] Pagination broken on PHP7.0.8 (Division by 0) #14387

alexhouse opened this issue Jul 20, 2016 · 6 comments

Comments

@alexhouse
Copy link

In the process of updating our composer libraries it seems Laravel 5.2.40 pagination breaks in at least PHP7.0.8.

It appears PHP7 can't handle assigning variables whilst assigning a variable. Problematic code:

    $results = $total ? $this->forPage(
        $page = $page ?: Paginator::resolveCurrentPage($pageName),
        $perPage = $perPage ?: $this->model->getPerPage()
    )->get($columns) : [];

Essentially, $page and $perPage end up as null and 0, causing LengthAwarePaginator to backflip over a division by 0.

This can be demonstrated through Tinker:

>>> $page = null;
>>> $perPage = null;
>>> $total = null;
>>> function noop($page, $perPage) {}
>>> $results = $total ? noop($page = $page ?: 1, $perPage = $perPage ?: 20) : [];
=> []
>>> dd($page, $perPage);
null
null

I imagine this is more of a PHP7 problem but Laravel could, in the meantime, revert to the previous implementation of Builder::paginate() which doesn't have this problem in order to resolve this issue.

@xuyu
Copy link

xuyu commented Jul 20, 2016

Same bug for me.
Use simplePaginate instead and wait it to be fixed.

commit: 41fd377

@ameliaikeda
Copy link
Contributor

This was broken by #14188

@themsaid
Copy link
Member

Why does your perPage = 0?

If you call ->paginat(10), $perPage will be 10.

if you call ->paginate(), $perPage will be equal to the model's perPage value.

@alexhouse
Copy link
Author

It shouldn't equal 0. It equals 20. Adding var_dumps or dds before the $results declaration shows that it should equal 20, but the assignment to the $perPage variable within the $results ternary turns it into 0.

Essentially the $perPage and $page assignments need to be done before they're then used in the function call.

We call paginate with no arguments.

@themsaid
Copy link
Member

Fix submitted #14389

@mnabialek
Copy link
Contributor

@alexhouse Sorry for that, I've introduced it when adding optimization for pagination, now fix by @themsaid is already included in latest release

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

No branches or pull requests

5 participants