--TEST-- Test <=> operator : different types --FILE-- true for example // also note that a string of "0" is converted to false but a string of "0.0" is converted to true // false cannot be tested as 0 can never be > 0 or 1 true, $valid_false, $valid_true, $int1, $valid_int1, $invalid_int1, $int2, $valid_int2, $invalid_int2, $float1, $valid_float1, $invalid_float1, $float2, $valid_float2, $invalid_float2 ); $failed = false; for ($i = 0; $i < count($toCompare); $i +=3) { $typeToTest = $toCompare[$i]; $valid_compares = $toCompare[$i + 1]; $invalid_compares = $toCompare[$i + 2]; foreach($valid_compares as $compareVal) { if (($typeToTest <=> $compareVal) === 1) { // do nothing } else { echo "FAILED: ('$typeToTest' <=> '$compareVal') !== 1\n"; $failed = true; } if (($compareVal <=> $typeToTest) === -1) { // do nothing } else { echo "FAILED: ('$compareVal' <=> '$typeToTest') !== -1\n"; $failed = true; } if (($compareVal <=> $compareVal) === 0) { // do nothing } else { echo "FAILED: ('$compareVal' <=> '$compareVal') !== 0\n"; $failed = true; } } foreach($invalid_compares as $compareVal) { if (($typeToTest <=> $compareVal) === 1) { echo "FAILED: ('$typeToTest' <=> '$compareVal') === 1\n"; $failed = true; } if (($compareVal <=> $typeToTest) === -1) { echo "FAILED: ('$compareVal' <=> '$typeToTest') === -1\n"; $failed = true; } if (($compareVal <=> $compareVal) !== 0) { echo "FAILED: ('$compareVal' <=> '$compareVal') !== 0\n"; $failed = true; } } if (($typeToTest <=> $typeToTest) === 0) { // do nothing } else { echo "FAILED: ('$typeToTest' <=> '$typeToTest') !== 0\n"; $failed = true; } } if ($failed == false) { echo "Test Passed\n"; } ?> --EXPECT-- Test Passed