Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[12.x] Fix division by zero when $perPage is 0 in LengthAwarePaginator #55958

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

Open
wants to merge 1 commit into
base: 12.x
Choose a base branch
Loading
from

Conversation

platoindebugmode
Copy link

Description

This pull request prevents a potential division by zero error in the LengthAwarePaginator constructor when $perPage is set to 0. Instead of attempting to divide by zero, the code now defaults the last page to 1 in such cases.

No breaking changes, fallback behavior is consistent with framework philosophy.

References

N/A – this was a direct edge case improvement.

@crynobone crynobone changed the title [12.x] Fix division by zero when $perPage is 0 in LengthAwarePaginator [12.x] Fix division by zero when $perPage is 0 in LengthAwarePaginator Jun 9, 2025
@NickSdot
Copy link
Contributor

NickSdot commented Jun 9, 2025

  • In what situations the value would ever be 0? Seems like a bug to me if that would happen.
  • If there really are valid situations, why don't you simple add a default value to the constructor argument instead of adding a control flow?

Copy link
Member

@GrahamCampbell GrahamCampbell left a comment

Choose a reason for hiding this comment

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

I don't think it makes sense to add this here. The fact that passing in zero causes a crash is what we want - we want people to know they have passed invalid input.

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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.