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

Should 'isset()' take empty arrays into account? #2

Open
AFoeee opened this issue Feb 17, 2022 · 1 comment
Open

Should 'isset()' take empty arrays into account? #2

AFoeee opened this issue Feb 17, 2022 · 1 comment

Comments

@AFoeee
Copy link

AFoeee commented Feb 17, 2022

I wonder whether it would make sense for isset() to take empty arrays into account?

If I correctly understand the application, it is used to check if a widget field is undefined, null or ''.
However, unpopulated media-input-fields with a "multiple" parameter set to true, can return an empty array, right?
(At least I get an empty array, when I delete all existing videos from a 'video-input' field.)

Of course, a user could simply implement something like the following:

// Uses the input of a media field to test whether media was added to it.
function isMediaFieldPopulated(input) {
  return (input && (Array.isArray(input) ? (input.length > 0) : true));
}
@reboot0-de
Copy link
Owner

The isset function was made in reference to the PHP counterpart.
For the specific case of this toolset, I just added an option to check for empty strings as well.
What you mean would be something like empty, but that is a very blunt function and might introduce some unexpected bugs, so I decided against it.

But yeah, I might add something specifically for (multiple) media-inputs in the future.
There are a few things I wanted to update anyways, when I find some time.

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

2 participants