Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions reference/array/functions/in-array.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,16 @@
</para>
<note>
<para>
Prior to PHP 8.0.0, a <literal>string</literal> <parameter>needle</parameter> will match an array
value of <literal>0</literal> in non-strict mode, and vice versa. That may lead to undesireable
results. Similar edge cases exist for other types, as well. If not absolutely certain of the
types of values involved, always use the <parameter>strict</parameter> flag to avoid unexpected behavior.
</para>
</note>
Prior to PHP 8.0.0, a <literal>string</literal> <parameter>needle</parameter> would loosely match
a numeric <parameter>haystack</parameter> value of <literal>0</literal>, and vice versa.
As of PHP 8.0.0, this behavior is restricted to numeric strings. However, non-strict mode
still employs loose comparison (<literal>==</literal>), which allows for matches across
unrelated types. For example, a boolean <constant>&true;</constant> value in the
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
unrelated types. For example, a boolean <constant>&true;</constant> value in the
unrelated types. For example, a boolean &true; value in the

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

FYI; This is the cause of why CI tests fail. Because &true; is an entity that already contains a <constant>

<parameter>haystack</parameter> will match any non-empty <literal>string</literal>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
<parameter>haystack</parameter> will match any non-empty <literal>string</literal>
<parameter>haystack</parameter> will match any truthy <literal>string</literal>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Tiny accuracy nit: "0" is technically a non-empty string but evaluates to false under PHP's loose comparison, so in_array("0", [true]) returns false (see the comparison table). "Any truthy string" would be more precise.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
<parameter>haystack</parameter> will match any non-empty <literal>string</literal>
<parameter>haystack</parameter> will match any non-empty <type>string</type>

<parameter>needle</parameter>. It is recommended to use the <parameter>strict</parameter>
flag to ensure type-safe results.
</para>
</note>
Comment on lines +66 to +67
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
</para>
</note>
</para>
</note>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should become <simpara> as well (instead of <para>

</listitem>
</varlistentry>
</variablelist>
Expand Down
Loading