Skip to content

Add constants to BC promise #5672

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 1 commit into from
Closed
Changes from all commits
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
15 changes: 15 additions & 0 deletions contributing/code/bc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ Add type hint to an argument No
Remove type hint of an argument No
Change argument type No
Change return type No
**Constants**
Add constant Yes
Remove constant No
Change value of a constant Yes [1]_ [5]_
============================================== ==============

Changing Classes
Expand Down Expand Up @@ -253,6 +257,10 @@ Change return type Yes
**Static Methods**
Turn non static into static No
Turn static into non static No
**Constants**
Add constant Yes
Remove constant No
Change value of a constant Yes [1]_ [5]_
================================================== ==============

.. [1] Should be avoided. When done, this change must be documented in the
Expand All @@ -267,6 +275,13 @@ Turn static into non static No
.. [4] When changing the parent class, the original parent class must remain an
ancestor of the class.

.. [5] The value of a constant may only be changed when the constants aren't
used in configuration (e.g. Yaml and XML files), as these do not support
Copy link
Contributor

Choose a reason for hiding this comment

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

Yaml should be removed until symfony/symfony#18626 is merged in 3.2

constants and have to hardcode the value. For instance, event name
constants can't change the value without introducing a BC break.
Copy link
Member

Choose a reason for hiding this comment

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

or when the value can be used in serialize/unserialize

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 can apply to any constant, isn't it?

Copy link
Member

Choose a reason for hiding this comment

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

I think Nicolas' point is probably that if a value will likely be used in serialize/unserialize, like if there were some constant that was commonly put onto User classes (since those are serialized). But this does highlight that this is slippery. Perhaps that this should be re-worded that changing constant values is discouraged, but is allowed if we're quite sure that it's not being used in configuration files or in objects that are serialized. Anyways, the "serialized" is a good point, because it might make us think about this in the future and realize that changing some constant value would be bad in one case :)

Copy link
Member

Choose a reason for hiding this comment

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

I think we should simply add:

Additionally, if a constant will likely be used in objects that are serialized, the value of
a constant should not be changed.

To your point Wouter, technically any constant could be used in a configuration file too - but there are a few that are very commonly used (i.e. it's a "main supported use-case") - and it's those that we should avoid).

Additionally, if a constant will likely be used in objects that are
serialized, the value of a constant should not be changed.

.. _Semantic Versioning: http://semver.org/
.. _scalar type: http://php.net/manual/en/function.is-scalar.php
.. _boolean values: http://php.net/manual/en/function.boolval.php
Expand Down