php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66607 Some tag keys are converted to integers
Submitted: 2014-01-29 23:24 UTC Modified: 2014-01-31 05:29 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: shoghicp at pocketmine dot net Assigned:
Status: Not a bug Package: yaml (PECL)
PHP Version: 5.5.8 OS: Windows 7
Private report: No CVE-ID: None
 [2014-01-29 23:24 UTC] shoghicp at pocketmine dot net
Description:
------------
Several tag keys are converted to an integer value (0 or 1) when the key can be interpreted as a boolean (like y, yes, true, off, no). This only happens when the tag is not quoted.

Test script:
---------------
<?php
$yaml = <<<YAML
- 
  x: 147
  y: 85
  z: 176
YAML;
var_dump(yaml_parse($yaml));

Expected result:
----------------
array(2) {
  [0]=>
  array(3) {
    ["x"]=>
    int(147)
    ["y"]=>
    int(85)
    ["z"]=>
    int(176)
  }
}

Actual result:
--------------
array(2) {
  [0]=>
  array(3) {
    ["x"]=>
    int(147)
    [1]=>
    int(85)
    ["z"]=>
    int(176)
  }
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-01-31 05:29 UTC] bd808@php.net
-Status: Open +Status: Not a bug
 [2014-01-31 05:29 UTC] bd808@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

I believe that this is actually the correct behavior according to the YAML 1.1 spec. Keys in a YAML mapping can be any type and the unquoted scalar strings listed at http://yaml.org/type/bool.html are treated as booleans. The mapping you give in your example is equivalent to `array( "x" => 147, true => 85, "z" => 176 )` which var_dump() describes in the same way as your actual result.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 02:01:30 2024 UTC