Skip to content

Add warnings about numeric strings in scientific notation #4407

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

Conversation

jimwins
Copy link
Member

@jimwins jimwins commented Jan 19, 2025

Comment on lines +88 to +103
<warning>
<simpara>
When using the <link linkend="language.operators.comparison">comparison
operator (<literal>==</literal>)</link>,
<link linkend="language.types.numeric-strings">numeric strings</link>
will be compared as numbers instead of as strings.
This means that <literal>"123" == " 123 "</literal> is &true;,
but also that <literal>"0e1234" == "0e5678"</literal> is &true;,
which can cause unexpected behavior when comparing hexidecimal strings
like those from <function>hash</function>.
The identity operator (<literal>===</literal>) or a string comparison
function, such as <function>strcmp</function> or
<function>hash_compare</function>, should be used to avoid unexpected
results.
</simpara>
</warning>
Copy link
Member

Choose a reason for hiding this comment

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

This should be in the comparative type juggling section, not the string one.

@kamil-tekiela
Copy link
Member

Isn't this all well-documented already? This foothole is probably as old as PHP and one the first things you learn. The documentation is pretty clear about the string comparison https://www.php.net/manual/en/language.operators.comparison.php

I am not against clarifying something that's unclear, but I don't know if adding another red box is truly necessary.

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.

4 participants