You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description
When trying to use a PHP class constant as a YAML key for a hash (as a method argument), I receive an ErrorException with the message Uninitialized string offset: 0 and code 8.
How to reproduce
Using the following class and Symfony YAML and DI I receive an ErrorException with the message Uninitialized string offset: 0 and code 8.
<?phpdeclare(strict_types=1);
namespaceVENDOR\PRODUCT;
class Example
{
publicconstCONSTANT_1 = 'constant_1';
publicconstCONSTANT_2 = 'constant_2';
private$Options;
publicfunctionaddOptions(array$options): Example
{
$this->Options[] = $options;
return$this;
}
}
Additional context
I am more than willing to bet that I am formatting the YAML incorrectly to accomplish this, but I have tried many variations of indentations and YAML hash expressions. Constants as YAML hash keys do work if I use them like the following. So my assumption of the behavior is that they should be able to be used for any valid YAML hash expression (like my example above).
I have quoted the constant for the key in my example above due to this comment. However, I have tried it without quoting and I receive an error about the colons (which I expect due to YAML processing).
Thank you =)
Update
I should probably also mention that the control case works as expected, i.e.
That's not supported because we don't support spaces in mapping keys, so in your example the key is !php/const which fails (with a bad message that could be improved). A solution would be to quote the key but we logically only evaluate non quoted keys so that's not a solution. Fixing this case is however possible.
I don't remember if we made a conscious decision not to support tags in making keys. We should check that first. Nonetheless, improving the reported error could still be done as a bugfix.
Symfony version(s) affected: 4.4.2
Description
When trying to use a PHP class constant as a YAML key for a hash (as a method argument), I receive an
ErrorException
with the messageUninitialized string offset: 0
and code8
.How to reproduce
Using the following class and Symfony YAML and DI I receive an
ErrorException
with the messageUninitialized string offset: 0
and code8
.Possible Solution
Additional context
I am more than willing to bet that I am formatting the YAML incorrectly to accomplish this, but I have tried many variations of indentations and YAML hash expressions. Constants as YAML hash keys do work if I use them like the following. So my assumption of the behavior is that they should be able to be used for any valid YAML hash expression (like my example above).
I have quoted the constant for the key in my example above due to this comment. However, I have tried it without quoting and I receive an error about the colons (which I expect due to YAML processing).
Thank you =)
Update
I should probably also mention that the control case works as expected, i.e.
The text was updated successfully, but these errors were encountered: