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
Problematic order of optional constructor parameters in AsContentElement/AsFrontendModule #4055
Comments
I found a discussion about this very topic #3619 (comment). But I don't agree with the outcome. 🙂 |
This is not a bug. As mentioned in the comment, this is intentional and makes sense to be consistent with annotations. Always use named parameters with (our) attributes. |
It does not work, though, even with named parameters unless you pass in at least two. So this is clearly a bug. |
What does not work? |
Did you read anything of what I wrote? You cannot construct the object with a single parameter, no matter if named or not.
|
I agree that this needs to be fixed. Only having to define the category and nothing else should be the minimum for the |
Can this be fixed by making category optional like Or use an actual default value like |
Yes, this would work. https://3v4l.org/TArPo#v8.1.2 But we could IMHO also just change the order - especially, if you should use named arguments anyways. |
As this parameter order was not released as stable yet, I agree we should change the order. |
By the way, having optional parameters before mandatory ones is deprecated since PHP8.0: https://php.watch/versions/8.0/deprecate-required-param-after-optional |
see #4065 |
…tructors (see #4065) Description ----------- Fixes #4055 This PR swaps the first two parameters of the `AsContentElement` and `AsFrontendModule` constructors. This was not released yet, so no BC issue. Background info: As of PHP8.0 having optional parameters before mandatory ones is deprecated. Here is an explanation why the current code did not trigger a deprecation warning and behaved just like two mandatory parameters: php/php-src#5067 (comment) Commits ------- 9058274 fix order of parameters 6df2476 adjust tests 5bd86a5 use miscellaneous as the default type and fix variadic argument type hint 4356ed6 prevent PHP<8.0 jobs from autoloading test cases with PHP8 syntax 8a1d2d8 add 'mixed' type hint for variadic attributes 1f396f9 improve comment 942fc37 Update core-bundle/tests/DependencyInjection/ContaoCoreExtensionTest.php e413bf3 🦊
Affected version(s)
4.13
Description
Our
AsContentElement
attribute currently looks like this:contao/core-bundle/src/DependencyInjection/Attribute/AsContentElement.php
Line 23 in 3691e1d
Having the first non-optional parameter at the second place forces you to define at least two parameters (https://3v4l.org/Y7N4G#v8.1.2), but with the content element attribute, you typically only define the
category
, which then results in:(Similar reasoning for
AsFrontendModule
.)@aschempp What's the reason for this unusual order? Can we change this?
The text was updated successfully, but these errors were encountered: