-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
[Contributing] [Standards] Added entry for identical comparison #5403
Conversation
phansys
commented
Jun 15, 2015
Q | A |
---|---|
Doc fix? | yes |
New docs? | no |
Applies to | 2.8+ |
Fixed tickets |
| Q | A | ------------- | --- | Doc fix? | yes | New docs? | no | Applies to | 2.8+ | Fixed tickets |
Comparisons | ||
----------- | ||
|
||
Use `identical comparison`_ when the expected value must match a specific type: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, strict comparison should be used everywhere except when you really need type juggling (in most cases, you don't want it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, the most common juggling is when null
or an empty string evaluated to false
.
I think this should be better placed in the coding standards page. the conventions page is mostly about naming conventions |
036261c
to
fc350ca
Compare
@stof, done. |
Comparisons | ||
----------- | ||
|
||
Use `identical comparison`_ when the expected value must match a specific type: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I asked the same previously (which disappeared when moving the note to a different page)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the original note from @stof about identical comparison.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, should be something like "Always use strict comparison unless you need type juggling".
Updated message to enforce always to use strict comparison. |
|
||
if (1 === $integerExpected) { | ||
// ... | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about using one code block for this to make it more compact?
Always use `identical comparison`_ unless you need type juggling::
// use
if (1 === $integerExcepted) {
// ...
}
// instead of
if (1 == $integerExcepted) {
// ...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems good to me @xabbuh.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
2f4d218
to
b0a441f
Compare
|
||
Always use `identical comparison`_ unless you need type juggling: | ||
|
||
.. code-block:: php |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can omit this if you use a double colon at the end of the line before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw that syntax before, but what about specific code highlighting for PHP?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PHP is the default syntax highlighting. So it's used in that case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
👍 |
Comparisons | ||
----------- | ||
|
||
Always use `identical comparison`_ unless you need type juggling:: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should put this in the list of standards as well, instead of a custom section
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean in structure section?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes (sorry if I was a bit too vague)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem at all, I'll try to update this PR and #5402 ASAP based in your suggestions.
Thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wouterj, updated.
+1 from my side (not 100% sure if "Always use ... unless ..." is better or worse than "Unless ..., always use ...", but I'll let our native speakers decide on that one 😉 ) |
Thank you Javier. |
…arison (phansys) This PR was submitted for the 2.8 branch but it was merged into the 2.3 branch instead (closes #5403). Discussion ---------- [Contributing] [Standards] Added entry for identical comparison | Q | A | ------------- | --- | Doc fix? | yes | New docs? | no | Applies to | 2.8+ | Fixed tickets | Commits ------- bacd22e [Contributing] [Standards] Added entry for identical comparison
Ryan can always tweak the text later if he disagrees. :) |