Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

--TEST-- Test that floats are converted to string locale independently --SKIPIF-- <?php i..

Decoded Output download

--TEST--
Test that floats are converted to string locale independently
--SKIPIF--
<?php

if (!setlocale
    (LC_ALL,
    "german", "de", "de_DE", "de_DE.ISO8859-1", "de_DE.ISO_8859-1", "de_DE.UTF-8",
    "french", "fr", "fr_FR", "fr_FR.ISO8859-1", "fr_FR.ISO_8859-1", "fr_FR.UTF-8",
    )) {
    die("skip - locale needed for this test is not supported on this platform");
}

?>
--FILE--
<?php

function print_float(float $f)
{
    echo "- casting:
";
    echo $f . "
";
    echo strval($f) . "
";
    $g = $f;
    settype($g, "string");
    echo $g . "
";

    echo "- *printf functions:
";
    printf("%.2f
", $f);
    printf("%.2F
", $f);
    echo sprintf("%.2f", $f) . "
";
    echo sprintf("%.2F", $f) . "
";

    echo "- export/import:
";
    echo var_export($f, true)  . "
";
    echo serialize($f) . "
";
    echo json_encode($f) . "
";

    echo "- debugging:
";
    echo print_r($f, true) . "
";
    var_dump($f);
    debug_zval_dump($f);

    echo "- other:
";
    echo implode([$f]) . "
";
}

setlocale(LC_ALL, "C");
echo "C locale:
";

print_float(3.14);

setlocale(
    LC_ALL,
    "german", "de", "de_DE", "de_DE.ISO8859-1", "de_DE.ISO_8859-1", "de_DE.UTF-8",
    "french", "fr", "fr_FR", "fr_FR.ISO8859-1", "fr_FR.ISO_8859-1", "fr_FR.UTF-8",
);
echo "
de_DE locale:
";

print_float(3.14);

?>
--EXPECT--
C locale:
- casting:
3.14
3.14
3.14
- *printf functions:
3.14
3.14
3.14
3.14
- export/import:
3.14
d:3.14;
3.14
- debugging:
3.14
float(3.14)
float(3.14)
- other:
3.14

de_DE locale:
- casting:
3.14
3.14
3.14
- *printf functions:
3,14
3.14
3,14
3.14
- export/import:
3.14
d:3.14;
3.14
- debugging:
3.14
float(3.14)
float(3.14)
- other:
3.14

Did this file decode correctly?

Original Code

--TEST--
Test that floats are converted to string locale independently
--SKIPIF--
<?php

if (!setlocale
    (LC_ALL,
    "german", "de", "de_DE", "de_DE.ISO8859-1", "de_DE.ISO_8859-1", "de_DE.UTF-8",
    "french", "fr", "fr_FR", "fr_FR.ISO8859-1", "fr_FR.ISO_8859-1", "fr_FR.UTF-8",
    )) {
    die("skip - locale needed for this test is not supported on this platform");
}

?>
--FILE--
<?php

function print_float(float $f)
{
    echo "- casting:\n";
    echo $f . "\n";
    echo strval($f) . "\n";
    $g = $f;
    settype($g, "string");
    echo $g . "\n";

    echo "- *printf functions:\n";
    printf("%.2f\n", $f);
    printf("%.2F\n", $f);
    echo sprintf("%.2f", $f) . "\n";
    echo sprintf("%.2F", $f) . "\n";

    echo "- export/import:\n";
    echo var_export($f, true)  . "\n";
    echo serialize($f) . "\n";
    echo json_encode($f) . "\n";

    echo "- debugging:\n";
    echo print_r($f, true) . "\n";
    var_dump($f);
    debug_zval_dump($f);

    echo "- other:\n";
    echo implode([$f]) . "\n";
}

setlocale(LC_ALL, "C");
echo "C locale:\n";

print_float(3.14);

setlocale(
    LC_ALL,
    "german", "de", "de_DE", "de_DE.ISO8859-1", "de_DE.ISO_8859-1", "de_DE.UTF-8",
    "french", "fr", "fr_FR", "fr_FR.ISO8859-1", "fr_FR.ISO_8859-1", "fr_FR.UTF-8",
);
echo "\nde_DE locale:\n";

print_float(3.14);

?>
--EXPECT--
C locale:
- casting:
3.14
3.14
3.14
- *printf functions:
3.14
3.14
3.14
3.14
- export/import:
3.14
d:3.14;
3.14
- debugging:
3.14
float(3.14)
float(3.14)
- other:
3.14

de_DE locale:
- casting:
3.14
3.14
3.14
- *printf functions:
3,14
3.14
3,14
3.14
- export/import:
3.14
d:3.14;
3.14
- debugging:
3.14
float(3.14)
float(3.14)
- other:
3.14

Function Calls

None

Variables

None

Stats

MD5 0e284e308dbd738f646385579bc3761e
Eval Count 0
Decode Time 93 ms