Skip to content

Add a notice to spl_object_hash() return values comparison #2607

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

Merged
merged 1 commit into from
Jul 28, 2023

Conversation

alexandre-daubois
Copy link
Contributor

Fix #2406

Comment on lines 75 to 79
Object hashes should always be strictly compared with <code>===</code> and
<code>!==</code>, because returned hashes could be a valid integer
representation like <code>0000000000000e600000000000000000</code> (which is
a valid integer representation using exponent notation). Not doing so may
lead to confusing and false comparisons.
Copy link
Member

Choose a reason for hiding this comment

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

Improve wording to use the name of the === operator, but also I don't know if saying this can lead to confusing comparison needs more detail if we mention (and link) to numeric strings.

Suggested change
Object hashes should always be strictly compared with <code>===</code> and
<code>!==</code>, because returned hashes could be a valid integer
representation like <code>0000000000000e600000000000000000</code> (which is
a valid integer representation using exponent notation). Not doing so may
lead to confusing and false comparisons.
Object hashes should be compared for identity with <code>===</code> and
<code>!==</code>, because the returned hash could be a
<link linkend="language.types.numeric-strings">numeric string</link>.
For example: <literal>0000000000000e600000000000000000</literal>.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's definitely better. It's updated, thanks for the suggestion!

@Girgias Girgias merged commit f7e42ed into php:master Jul 28, 2023
@Girgias
Copy link
Member

Girgias commented Jul 28, 2023

Thank you!

nielsdos pushed a commit to nielsdos/doc-en that referenced this pull request Jul 29, 2023
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.

Add notice that output of spl_object_hash() should only be compared type safe
2 participants