Symfony version(s) affected: 4.4.7
Description
Virtually the same as #35179 but with different exceptions.
When trying to use a PHP class constant as a YAML key for a hash (as a method argument), I receive one of the following.
- a
\Symfony\Component\Yaml\Exception\ParseException with the message The constant "\VENDOR\PRODUCT\Example" is not defined at line 7 (near "!php/const \VENDOR\PRODUCT\Example"). if I use YAML Variant A below.
- a
\Symfony\Component\Yaml\Exception\ParseException with the message Malformed inline YAML string: ""\VENDOR\PRODUCT\Example" at line 7 (near ""\VENDOR\PRODUCT\Example"). if I use YAML Variant B below. I observe the same behavior when using single quotes.
How to reproduce
Using the following class and Symfony YAML DI files produces the above.
<?php
declare(strict_types=1);
namespace VENDOR\PRODUCT;
class Example
{
public const CONSTANT_1 = 'constant_1';
public const CONSTANT_2 = 'constant_2';
private $Options;
public function addOptions(array $options): Example
{
$this->Options[] = $options;
return $this;
}
}
# YAML Variant A
services:
VENDOR\PRODUCT\Example:
class: VENDOR\PRODUCT\Example
public: false # probably unrelated
shared: true # probably unrelated
calls:
- [addOptions, [{
!php/const \VENDOR\PRODUCT\Example::CONSTANT_1: 'value_0',
key_1: "value_1",
key_2: "value_2"
}]]
# YAML Variant B
services:
VENDOR\PRODUCT\Example:
class: VENDOR\PRODUCT\Example
public: false # probably unrelated
shared: true # probably unrelated
calls:
- [addOptions, [{
!php/const "\VENDOR\PRODUCT\Example::CONSTANT_1": 'value_0',
key_1: "value_1",
key_2: "value_2"
}]]
Also, the control case and global PHP constants (in both variants) work as expected, i.e:
# YAML Variant A
services:
VENDOR\PRODUCT\Example:
class: VENDOR\PRODUCT\Example
public: false # probably unrelated
shared: true # probably unrelated
calls:
- [addOptions, [{
!php/const PHP_INT_MAX: "value_0",
key_1: "value_1",
key_2: "value_2"
}]]
# YAML Variant B
services:
VENDOR\PRODUCT\Example:
class: VENDOR\PRODUCT\Example
public: false # probably unrelated
shared: true # probably unrelated
calls:
- [addOptions, [{
!php/const "PHP_INT_MAX": "value_0",
key_1: "value_1",
key_2: "value_2"
}]]
Symfony version(s) affected: 4.4.7
Description
Virtually the same as #35179 but with different exceptions.
When trying to use a PHP class constant as a YAML key for a hash (as a method argument), I receive one of the following.
\Symfony\Component\Yaml\Exception\ParseExceptionwith the messageThe constant "\VENDOR\PRODUCT\Example" is not defined at line 7 (near "!php/const \VENDOR\PRODUCT\Example").if I use YAML Variant A below.\Symfony\Component\Yaml\Exception\ParseExceptionwith the messageMalformed inline YAML string: ""\VENDOR\PRODUCT\Example" at line 7 (near ""\VENDOR\PRODUCT\Example").if I use YAML Variant B below. I observe the same behavior when using single quotes.How to reproduce
Using the following class and Symfony YAML DI files produces the above.
Also, the control case and global PHP constants (in both variants) work as expected, i.e: