Skip to content

[Contributing] [Standards] Added entry for identical comparison #5403

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

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
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
25 changes: 25 additions & 0 deletions contributing/code/conventions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,29 @@ must be used instead (where ``XXX`` is the name of the related thing):
"replaceXXX", on the other hand, cannot add new elements. If an unrecognized
key is passed to "replaceXXX" it must throw an exception.

.. _contributing-code-conventions-comparisons:

Comparisons
-----------

Use `identical comparison`_ when the expected value must match a specific type:
Copy link
Member

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)

Copy link
Contributor Author

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.


instead of:

.. code-block:: php

if (1 == $integerExpected) {
// ...
}

it should be:

.. code-block:: php

if (1 === $integerExpected) {
// ...
}

.. _contributing-code-conventions-deprecations:

Deprecations
Expand Down Expand Up @@ -104,3 +127,5 @@ the migration starting one or two minor versions before the version where the
feature will be removed (depending on the criticality of the removal)::

trigger_error('XXX() is deprecated since version 2.X and will be removed in 2.Y. Use XXX instead.', E_USER_DEPRECATED);

.. _`identical comparison`: https://php.net/manual/en/language.operators.comparison.php