Closed
Description
Q | A |
---|---|
Bug report? | no |
Feature request? | no |
BC Break report? | yes |
RFC? | no |
Symfony version | 3.3.2 |
The YAML linter throws the error "Implicit casting of incompatible key type to string on line X is deprecated since version 3.3" when we use !php/const in keys, even if the value of the constant is a string since #21774. Is it the intended behavior? I don't fully understand the YAML specification on that regard.
Here's an example:
config.yml:
!php/const:MyClass::TEST: "bar"
baz: !php/const:MyClass::TEST
console.php:
use Symfony\Component\Console\Application;
use Symfony\Component\Yaml\Command\LintCommand;
class MyClass
{
const TEST = 'foo';
}
$application = new Application('echo', '1.0.0');
$command = new LintCommand();
$application->add($command);
$application->setDefaultCommand($command->getName(), true);
$application->run();
php console.php const.yml
3.2.9 output:
[OK] All 1 YAML files contain valid syntax.
3.3.2 output:
ERROR in const.yml
>> Implicit casting of incompatible key type to string on line 0 is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Pass the PARSE_KEYS_AS_STRING flag to explicitly enable the type casts.
[WARNING] 0 YAML files have valid syntax and 1 contain errors.
However, the Yaml parser correctly parse the file with or without PARSE_KEYS_AS_STRING flag.
use Symfony\Component\Yaml\Parser;
use Symfony\Component\Yaml\Yaml;
$parser = new Parser();
class MyClass
{
const TEST = 'foo';
}
$yaml = <<<'EOF'
!php/const:MyClass::TEST: "bar"
baz: !php/const:MyClass::TEST
EOF;
print_r($parser->parse($yaml, Yaml::PARSE_CONSTANT));
/*
SF 3.2.9 and 3.3.2 :
Array
(
[foo] => bar
[baz] => foo
)
*/
Metadata
Metadata
Assignees
Labels
No labels