Skip to content

Comments

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

Merged
Girgias merged 1 commit intophp:masterfrom
alexandre-daubois:spl-object-hash-notice
Jul 28, 2023
Merged

Add a notice to spl_object_hash() return values comparison#2607
Girgias merged 1 commit intophp:masterfrom
alexandre-daubois:spl-object-hash-notice

Conversation

@alexandre-daubois
Copy link
Member

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
Member 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!

ndossche pushed a commit to ndossche/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