mustangostang / spyc

A simple YAML loader/dumper class for PHP
MIT License
701 stars 206 forks source link

Dumping floats in "comma locales" results in a string value #74

Open lukasbestle opened 5 years ago

lukasbestle commented 5 years ago

We use Spyc for Kirby CMS and have stumbled upon an issue that only occurs if PHP's number locale is set to a locale that uses commas as a decimal separator (like German for example).

Consider the following simple test case:

<?php

require_once 'Spyc.php';

$data = ['key' => 1.23];

// basic example
$yaml = Spyc::YAMLDump($data, false, false, true);
echo $yaml; // key: 1.23

// switch to a different locale that uses
// comma as decimal separator
setlocale(LC_NUMERIC, 'de_DE');

// Spyc now uses that for the YAML output as well,
// even though it shouldn't
$yaml = Spyc::YAMLDump($data, false, false, true);
echo $yaml; // key: '1,23'

As you can see, the output of Spyc differs even though the input value (a simple float) is the same.

We made a temporary fix in Kirby, maybe that's of use to you or maybe there's a better solution for this all-together.