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

WIP all_empty and any_empty#14334

Closed
elminson wants to merge 2 commits into
php:masterphp/php-src:masterfrom
elminson:testing_all_empty_any_emptyelminson/php-src:testing_all_empty_any_emptyCopy head branch name to clipboard
Closed

WIP all_empty and any_empty#14334
elminson wants to merge 2 commits into
php:masterphp/php-src:masterfrom
elminson:testing_all_empty_any_emptyelminson/php-src:testing_all_empty_any_emptyCopy head branch name to clipboard

Conversation

@elminson
Copy link
Copy Markdown

My proposal involves the introduction of two new methods, any_empty and all_empty, for working with arrays. These methods are designed to provide boolean outputs indicating whether any of the elements in an array are empty, or if all elements are empty, respectively. I believe these methods will be valuable additions to PHP’s array manipulation functionalities.

Below is a brief overview of the proposed methods:

any_empty(array $array): bool - This method will return true if any element in the provided array is empty, and false otherwise.
all_empty(array $array): bool - This method will return true if all elements in the provided array are empty, and false otherwise.
These methods aim to simplify common array checks and improve code readability and efficiency.

@NattyNarwhal
Copy link
Copy Markdown
Member

You should probably go through an RFC for new user-visible features. The RFC process will help you refine the scope and implementation.

@elminson
Copy link
Copy Markdown
Author

You should probably go through an RFC for new user-visible features. The RFC process will help you refine the scope and implementation.

@NattyNarwhal I will do it! thank you!

@TimWolla
Copy link
Copy Markdown
Member

In fact the implementation of this PR appears to match the PR #14108 (without giving credit), which is the PR for this RFC that is currently in voting: https://wiki.php.net/rfc/array_find

Personally I do not find it useful to have extra functions specifically for working with empty(). The semantics of empty() are terrible and it can easily be replicated in userland with

array_all($array, fn ($v) => empty($v));

@elminson
Copy link
Copy Markdown
Author

elminson commented May 27, 2024

My original branch was created on Feb 5 but never got the change to finish i, closing this PR

@elminson elminson closed this May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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.