Skip to content

Conversation

@Lassombria
Copy link
Contributor

No description provided.

['The function in_array must be used in strict mode.', 28],
['The function in_array must be used in strict mode.', 31],
['The function in_array must be used in strict mode.', 33],
['The function in_array must be used in strict mode.', 35],
Copy link
Contributor

Choose a reason for hiding this comment

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

No correct, because if we check object, object also checks hash too, as result, we can not use strict mode for enums, because enums is objects. We must use strict checks for scalar, as example 1 !== "1" or true !== 1.

// correct
\in_array(1, [1, 2, 3], true); // Because check scalars, and 1 !== "1".

$a = "1";
\in_array($a, [1, 2, 3], true);

$enum = SomeEnum::Bla;
\in_array($enum, [SomeEnum::Bla, SomeEnum::Foo, SomeEnum::Bar]); // correct because enum is not scalar and php correct check by "hashes".

@ZhukV ZhukV merged commit 3d8c03c into FiveLab:master Apr 25, 2025
5 checks passed
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.

2 participants