Skip to content

Change the deprecation message for null attribute values#3307

Open
mpdude wants to merge 8 commits intosymfony:2.xfrom
mpdude:change-null-attribute
Open

Change the deprecation message for null attribute values#3307
mpdude wants to merge 8 commits intosymfony:2.xfrom
mpdude:change-null-attribute

Conversation

@mpdude
Copy link

@mpdude mpdude commented Jan 19, 2026

Q A
Bug fix? no
New feature? yes
Deprecations? no
Documentation? no
Issues First step towards #3261, final fix can only happen in 3.x
License MIT

This PR changes the announcement of what null attribute values will mean in 3.x.

The plan towards fixing #3261 is as follows:

In 2.x:

  • null values are treated as true, giving the deprecation notice
  • Users need to pass true to keep the current behavior and make the notice go away

In 3.x:

  • Make a null value (as well as false) omit the attribute
  • aria-* attributes with a false value will trigger a deprecation notice, saying that it will be "false" in 4.0. To omit the aria-* attribute, null shall be used and will make the notice go away.

In 4.x:

@mpdude mpdude requested a review from Kocal as a code owner January 19, 2026 10:07
@carsonbot carsonbot added Feature New Feature Status: Needs Review Needs to be reviewed labels Jan 19, 2026
@carsonbot carsonbot changed the title Change the deprecation message for null attribute values Change the deprecation message for null attribute values Jan 19, 2026
if (null === $value) {
trigger_deprecation('symfony/ux-twig-component', '2.8.0', 'Passing "null" as an attribute value is deprecated and will throw an exception in 3.0.');
trigger_deprecation('symfony/ux-twig-component', '2.32.0', 'Passing null as value for the %s attribute will omit the attribute in 3.0. To keep the current result, pass true instead.', $key);
$value = true;
Copy link
Member

Choose a reason for hiding this comment

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

Not sure we should precise the key... I mean maybe we should not suggest passing null is deprecated for that attribute only.

"To keep the current result, pass true instead."

I think with the various changes we plan, we should avoid using "current" / "previous" / "next" or maintaining (or reading) the docs will become quickly really hard.

What about something like "Use true to add the attribute, null or false to remove it"

Copy link
Author

Choose a reason for hiding this comment

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

I will try to reword that.

My initial idea was that it might make it easier for users to understand which attribute to search for. But I also realized that people might be collecting and grouping deprecation messages by type, and so having a different message for each attribute might not be helpful to them either.

Also, for example the XmlFileReader deprecated in Symfony 7.4 only says XML is deprecated but does not give the file name. So, omitting the attribute name will be in line with that.

Copy link
Author

@mpdude mpdude Jan 20, 2026

Choose a reason for hiding this comment

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

Now it's

Passing null as value to set an attribute is deprecated, pass true instead. In 3.0, the null value will remove the attribute.

Copy link
Member

@Kocal Kocal left a comment

Choose a reason for hiding this comment

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

Thanks you for working on this!

aria-* attributes with a false value will trigger a deprecation notice, saying that it will be "false" in 4.0 (...)

Couldn't it be done in 3.x?

@mpdude
Copy link
Author

mpdude commented Jan 21, 2026

Couldn't it be done in 3.x?

I don't think so, but I haven't tried it, only looking at the code.

In 2.x, false means to omit attributes, and null (still) is equal to true (and should print "true" for aria-*).

So if users would get a deprecation notice in 2.x, telling them that false for aria-* would not omit the attribute in 3.0 but print "false" instead – there is no other value that they could migrate to (in 2.x) to keep the effect of omitting the attribute. Remember, null still results in true.

Thus I think we need the change here to give ourselves a little more legroom in 3.0 and something users could switch their aria-*: false values to.

Am I missing something?

@mpdude
Copy link
Author

mpdude commented Jan 21, 2026

Not sure about test failures, seem unrelated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature New Feature Status: Needs Review Needs to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants