Skip to content

chore: remove occurrences of empty() #374

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: main
Choose a base branch
from

Conversation

alexandre-daubois
Copy link

empty() is used less and less in favor of bool casts on arrays. Symfony, for example, banned it from its codebase. I suggest we remove them from here as well.

@DZunke
Copy link
Contributor

DZunke commented Jul 3, 2025

May i ask why those bool casts are favored instead of replacing empty by explicit checks? I understand the downsides of empty but it feels weared to check if an empty array is false instead of explicit check like \count($foo) === 0.

I just try to understand the pro and con of this variant 🤔

@alexandre-daubois
Copy link
Author

I'm in favor of removing empty(), but I'm also fine using \count($foo) === 0 to check array emptiness. The main difference is that by using a bool cast, this check is performed at the engine level instead of userland, which makes it more efficient. I can understand performance in not what matters the most here, and I can update the PR to use count() if you prefer. As long as empty() is avoided 😄

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