Skip to content

Commit bc6329b

Browse files
rvanlaakfabpot
authored andcommitted
[Yaml] Clarify "incompatible key casting" deprecation message
1 parent 885db86 commit bc6329b

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

Parser.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ private function doParse($value, $flags)
237237
}
238238

239239
if (!(Yaml::PARSE_KEYS_AS_STRINGS & $flags) && !is_string($key)) {
240-
@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_STRING flag to explicitly enable the type casts.', E_USER_DEPRECATED);
240+
$keyType = is_numeric($key) ? 'numeric key' : 'incompatible key type';
241+
@trigger_error(sprintf('Implicit casting of %s to string on line %d 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.', $keyType, $this->getRealCurrentLineNb()), E_USER_DEPRECATED);
241242
}
242243

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

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 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_STRING flag to explicitly enable the type casts.
1084+
* @expectedDeprecation Implicit casting of numeric key to string on line 1 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.
10851085
*/
10861086
public function testFloatKeys()
10871087
{
@@ -1103,7 +1103,7 @@ public function testFloatKeys()
11031103

11041104
/**
11051105
* @group legacy
1106-
* @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_STRING flag to explicitly enable the type casts.
1106+
* @expectedDeprecation Implicit casting of incompatible key type to string on line 1 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.
11071107
*/
11081108
public function testBooleanKeys()
11091109
{

0 commit comments

Comments
 (0)