Skip to content

Commit ddc2332

Browse files
committed
Suggest using quotes instead of Yaml::PARSE_KEYS_AS_STRINGS
1 parent 1f93a8d commit ddc2332

File tree

5 files changed

+10
-13
lines changed

5 files changed

+10
-13
lines changed

CHANGELOG.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,14 @@ CHANGELOG
99

1010
* Deprecated support for implicitly parsing non-string mapping keys as strings.
1111
Mapping keys that are no strings will lead to a `ParseException` in Symfony
12-
4.0. Use the `PARSE_KEYS_AS_STRINGS` flag to opt-in for keys to be parsed as
13-
strings.
12+
4.0. Use quotes to opt-in for keys to be parsed as strings.
1413

1514
Before:
1615

1716
```php
1817
$yaml = <<<YAML
1918
null: null key
2019
true: boolean true
21-
1: integer key
2220
2.0: float key
2321
YAML;
2422

@@ -30,13 +28,12 @@ CHANGELOG
3028
```php
3129

3230
$yaml = <<<YAML
33-
null: null key
34-
true: boolean true
35-
1: integer key
36-
2.0: float key
31+
"null": null key
32+
"true": boolean true
33+
"2.0": float key
3734
YAML;
3835

39-
Yaml::parse($yaml, Yaml::PARSE_KEYS_AS_STRINGS);
36+
Yaml::parse($yaml);
4037
```
4138

4239
* Omitted mapping values will be parsed as `null`.

Inline.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar
494494
$evaluatedKey = self::evaluateScalar($key, $flags, $references);
495495

496496
if ('' !== $key && $evaluatedKey !== $key && !is_string($evaluatedKey) && !is_int($evaluatedKey)) {
497-
@trigger_error('Implicit casting of incompatible mapping keys to strings is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Pass the PARSE_KEYS_AS_STRINGS flag to explicitly enable the type casts.', E_USER_DEPRECATED);
497+
@trigger_error('Implicit casting of incompatible mapping keys to strings is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Quote your evaluable mapping keys instead.', E_USER_DEPRECATED);
498498
}
499499
}
500500

Parser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ private function doParse($value, $flags)
238238

239239
if (!(Yaml::PARSE_KEYS_AS_STRINGS & $flags) && !is_string($key) && !is_int($key)) {
240240
$keyType = is_numeric($key) ? 'numeric key' : 'non-string key';
241-
@trigger_error(sprintf('Implicit casting of %s to string is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Pass the PARSE_KEYS_AS_STRINGS flag to explicitly enable the type casts.', $keyType), E_USER_DEPRECATED);
241+
@trigger_error(sprintf('Implicit casting of %s to string is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Quote your evaluable mapping keys instead.', $keyType), E_USER_DEPRECATED);
242242
}
243243

244244
// Convert float keys to strings, to avoid being converted to integers by PHP

Tests/InlineTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ public function testTheEmptyStringIsAValidMappingKey()
730730

731731
/**
732732
* @group legacy
733-
* @expectedDeprecation Implicit casting of incompatible mapping keys to strings is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Pass the PARSE_KEYS_AS_STRINGS flag to explicitly enable the type casts.
733+
* @expectedDeprecation Implicit casting of incompatible mapping keys to strings is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Quote your evaluable mapping keys instead.
734734
* @dataProvider getNotPhpCompatibleMappingKeyData
735735
*/
736736
public function testImplicitStringCastingOfMappingKeysIsDeprecated($yaml, $expected)

Tests/ParserTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,7 @@ public function testYamlDirective()
10811081

10821082
/**
10831083
* @group legacy
1084-
* @expectedDeprecation Implicit casting of numeric key to string is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Pass the PARSE_KEYS_AS_STRINGS flag to explicitly enable the type casts.
1084+
* @expectedDeprecation Implicit casting of numeric key to string is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Quote your evaluable mapping keys instead.
10851085
*/
10861086
public function testFloatKeys()
10871087
{
@@ -1103,7 +1103,7 @@ public function testFloatKeys()
11031103

11041104
/**
11051105
* @group legacy
1106-
* @expectedDeprecation Implicit casting of non-string key to string is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Pass the PARSE_KEYS_AS_STRINGS flag to explicitly enable the type casts.
1106+
* @expectedDeprecation Implicit casting of non-string key to string is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Quote your evaluable mapping keys instead.
11071107
*/
11081108
public function testBooleanKeys()
11091109
{

0 commit comments

Comments
 (0)