php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #80630 Zend/tests/runtime_compile_time_binary_operands.phpt failed
Submitted: 2021-01-15 12:49 UTC Modified: 2021-05-04 11:46 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: ravi_salamani at gmail dot com Assigned:
Status: Closed Package: Testing related
PHP Version: 8.0.1 OS: RHEL 7.x/8.x
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
36 - 5 = ?
Subscribe to this entry?

 
 [2021-01-15 12:49 UTC] ravi_salamani at gmail dot com
Description:
------------
PHP Version: v8.0.1
Failure is observed on big-endian system on rhel distributions.

php:
<?php

$binaryOperators = [
    "==",
    "!=",
    "===",
    "!==",
    "<",
    "<=",
    ">",
    ">=",
    "<=>",
    "+",
    "-",
    "*",
    "/",
    "%",
    "**",
    ".",
    "|",
    "&",
    "^",
    "or",
    "and",
    "xor",
    "||",
    "&&",
];
$unaryOperators = [
    "~",
    "-",
    "+",
    "!",
];

$input = [
    0,
    1,
    2,
    -1,
    2.0,
    2.1,
    -2.0,
    -2.1,
    PHP_INT_MAX,
    PHP_INT_MIN,
    PHP_INT_MAX * 2,
    PHP_INT_MIN * 2,
    INF,
    NAN,
    [],
    [1, 2],
    [1, 2, 3],
    [1 => 2, 0 => 1],
    [1, 'a' => 2],
    [1, 4],
    [1, 'a'],
    [1, 2 => 2],
    [1, [ 2 ]],
    null,
    false,
    true,
    "",
    " ",
    "banana",
    "Banana",
    "banan",
    "0",
    "200",
    "20",
    "20a",
    " \t\n\r\v\f20",
    "20  ",
    "2e1",
    "2e150",
    "9179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368",
    "-9179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368",
    "0.1",
    "-0.1",
    "1e-1",
    "-20",
    "-20.0",
    "0x14",
    (string) PHP_INT_MAX * 2,
    (string) PHP_INT_MIN * 2,
];

function makeParam($param) {
    if ($param === PHP_INT_MIN) {
        return "PHP_INT_MIN";
    }
    if ($param === PHP_INT_MAX) {
        return "PHP_INT_MAX";
    }
    if (is_string($param)) {
        return '"' . strtr($param, ["\t" => '\t', "\n" => '\n', "\r" => '\r', "\v" => '\v', "\f" => '\f', '$' => '\$', '"' => '\"']) . '"';
    }
    return "(" . str_replace("\n", "", var_export($param, true)) . ")";
}

$c = 0;
$f = 0;

function prepareBinaryLine($op1, $op2, $cmp, $operator) {
    $op1_p = makeParam($op1);
    $op2_p = makeParam($op2);

    $error = "echo '" . addcslashes("$op1_p $operator $op2_p", "\\'") . '\', "\n"; $f++;';

    $compare = "@($op1_p $operator $op2_p)";
    $line = "\$c++; ";
    try {
        $result = makeParam($cmp());
        $line .= "if (" . ($result === "(NAN)" ? "!is_nan($compare)" : "$compare !== $result") . ") { $error }";
    } catch (Error $e) {
        $msg = makeParam($e->getMessage());
        $line .= "try { $compare; $error } catch (Error \$e) { if (\$e->getMessage() !== $msg) { $error } }";
    }
    return $line;
}
function prepareUnaryLine($op, $cmp, $operator) {
    $op_p = makeParam($op);

    $error = "echo '" . addcslashes("$operator $op_p", "\\'") . '\', "\n"; $f++;';

    $compare = "@($operator $op_p)";
    $line = "\$c++; ";
    try {
        $result = makeParam($cmp());
        $line .= "if (" . ($result === "(NAN)" ? "!is_nan($compare)" : "$compare !== $result") . ") { $error }";
    } catch (Error $e) {
        $msg = makeParam($e->getMessage());
        $line .= "try { $compare; $error } catch (Error \$e) { if (\$e->getMessage() !== $msg) { $error } }";
    }
    return $line;
}

$filename = __DIR__ . DIRECTORY_SEPARATOR . 'compare_binary_operands_temp.php';
$file = fopen($filename, "w");

fwrite($file, "<?php\n");

foreach ($input as $left) {
    foreach ($input as $right) {
        foreach ($binaryOperators as $operator) {
            $line = prepareBinaryLine($left, $right, function() use ($left, $right, $operator) {
                return eval("return @(\$left $operator \$right);");
            }, $operator);
            fwrite($file, $line . "\n");
        }
    }
}
foreach ($input as $right) {
    foreach ($unaryOperators as $operator) {
        $line = prepareUnaryLine($right, function() use ($right, $operator) {
            return eval("return @($operator \$right);");
        }, $operator);
        fwrite($file, $line . "\n");
    }
}

fclose($file);

include $filename;

if($c === 0) {
    echo "Completely failed\n";
} else {
    echo "Failed: $f\n";
}
?>


Expected result:
----------------
Failed: 0

Actual result:
--------------
(0) < (NAN)
(0) <= (NAN)
(0) > (NAN)
(0) >= (NAN)
(1) < (NAN)
(1) <= (NAN)
(1) > (NAN)
(1) >= (NAN)
(2) < (NAN)
(2) <= (NAN)
(2) > (NAN)
(2) >= (NAN)
(-1) < (NAN)
(-1) <= (NAN)
(-1) > (NAN)
(-1) >= (NAN)
(2.0) < (NAN)
(2.0) <= (NAN)
(2.0) > (NAN)
(2.0) >= (NAN)
(2.1) < (NAN)
(2.1) <= (NAN)
(2.1) > (NAN)
(2.1) >= (NAN)
(-2.0) < (NAN)
(-2.0) <= (NAN)
(-2.0) > (NAN)
(-2.0) >= (NAN)
(-2.1) < (NAN)
(-2.1) <= (NAN)
(-2.1) > (NAN)
(-2.1) >= (NAN)
PHP_INT_MAX < (NAN)
PHP_INT_MAX <= (NAN)
PHP_INT_MAX > (NAN)
PHP_INT_MAX >= (NAN)
PHP_INT_MIN < (NAN)
PHP_INT_MIN <= (NAN)
PHP_INT_MIN > (NAN)
PHP_INT_MIN >= (NAN)
(1.8446744073709552E+19) < (NAN)
(1.8446744073709552E+19) <= (NAN)
(1.8446744073709552E+19) > (NAN)
(1.8446744073709552E+19) >= (NAN)
(-1.8446744073709552E+19) < (NAN)
(-1.8446744073709552E+19) <= (NAN)
(-1.8446744073709552E+19) > (NAN)
(-1.8446744073709552E+19) >= (NAN)
(INF) < (NAN)
(INF) <= (NAN)
(INF) > (NAN)
(INF) >= (NAN)
(NAN) < (0)
(NAN) <= (0)
(NAN) > (0)
(NAN) >= (0)
(NAN) < (1)
(NAN) <= (1)
(NAN) > (1)
(NAN) >= (1)
(NAN) < (2)
(NAN) <= (2)
(NAN) > (2)
(NAN) >= (2)
(NAN) < (-1)
(NAN) <= (-1)
(NAN) > (-1)
(NAN) >= (-1)
(NAN) < (2.0)
(NAN) <= (2.0)
(NAN) > (2.0)
(NAN) >= (2.0)
(NAN) < (2.1)
(NAN) <= (2.1)
(NAN) > (2.1)
(NAN) >= (2.1)
(NAN) < (-2.0)
(NAN) <= (-2.0)
(NAN) > (-2.0)
(NAN) >= (-2.0)
(NAN) < (-2.1)
(NAN) <= (-2.1)
(NAN) > (-2.1)
(NAN) >= (-2.1)
(NAN) < PHP_INT_MAX
(NAN) <= PHP_INT_MAX
(NAN) > PHP_INT_MAX
(NAN) >= PHP_INT_MAX
(NAN) < PHP_INT_MIN
(NAN) <= PHP_INT_MIN
(NAN) > PHP_INT_MIN
(NAN) >= PHP_INT_MIN
(NAN) < (1.8446744073709552E+19)
(NAN) <= (1.8446744073709552E+19)
(NAN) > (1.8446744073709552E+19)
(NAN) >= (1.8446744073709552E+19)
(NAN) < (-1.8446744073709552E+19)
(NAN) <= (-1.8446744073709552E+19)
(NAN) > (-1.8446744073709552E+19)
(NAN) >= (-1.8446744073709552E+19)
(NAN) < (INF)
(NAN) <= (INF)
(NAN) > (INF)
(NAN) >= (INF)
(NAN) < (NAN)
(NAN) <= (NAN)
(NAN) > (NAN)
(NAN) >= (NAN)
(NAN) < (1.8446744073709552E+19)
(NAN) <= (1.8446744073709552E+19)
(NAN) > (1.8446744073709552E+19)
(NAN) >= (1.8446744073709552E+19)
(NAN) < (-1.8446744073709552E+19)
(NAN) <= (-1.8446744073709552E+19)
(NAN) > (-1.8446744073709552E+19)
(NAN) >= (-1.8446744073709552E+19)
(1.8446744073709552E+19) < (NAN)
(1.8446744073709552E+19) <= (NAN)
(1.8446744073709552E+19) > (NAN)
(1.8446744073709552E+19) >= (NAN)
(-1.8446744073709552E+19) < (NAN)
(-1.8446744073709552E+19) <= (NAN)
(-1.8446744073709552E+19) > (NAN)
(-1.8446744073709552E+19) >= (NAN)
Failed: 124

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-01-19 15:09 UTC] nikic@php.net
On which CPU architecture is this?

I do know this test works on s390x, which is bid endian as well.
 [2021-01-25 16:04 UTC] nikic@php.net
-Status: Open +Status: Feedback
 [2021-01-26 18:20 UTC] simrit dot kaur at ibm dot com
I am facing this as well on RHEL Distros.
I have tested on RHEL 7.8, 7.9, 8.1, 8.2 and 8.3 with s390x arch.
PHP release version: 8.0.1
 [2021-02-03 10:35 UTC] ravi_salamani at gmail dot com
I am still facing issue for s390x for  RHEL distributions (RHEL 7.8/7.9/8.1/8.2/8.3)
 [2021-02-03 11:55 UTC] cmb@php.net
-Status: Feedback +Status: Open
 [2021-02-10 22:08 UTC] simrit dot kaur at ibm dot com
An interesting find, On further debugging these TC failures, I could see that on using gcc/cc version 10.2.0 or higher solves this problem for s390x arch.
 [2021-05-04 11:46 UTC] ravi_salamani at gmail dot com
-Status: Open +Status: Closed
 [2021-05-04 11:46 UTC] ravi_salamani at gmail dot com
Updating gcc/cc version 10.2.0 or higher is worked for me.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 02:01:30 2024 UTC