1--TEST--
2Test array_key_exists() function : usage variations - floats and casting to ints
3--FILE--
4<?php
5/*
6 * Pass floats as $key argument, then cast float values
7 * to integers and pass as $key argument
8 */
9
10echo "*** Testing array_key_exists() : usage variations ***\n";
11
12$keys = array(1.2345678900E-10, 1.00000000000001, 1.99999999999999);
13
14$search = array ('zero', 'one', 'two');
15
16$iterator = 1;
17foreach($keys as $key) {
18    echo "\n-- Iteration $iterator --\n";
19    echo "Pass float as \$key:\n";
20    try {
21        var_dump(array_key_exists($key, $search));
22    } catch (TypeError $exception) {
23        echo $exception->getMessage() . "\n";
24    }
25    echo "Cast float to int:\n";
26    var_dump(array_key_exists((int)$key, $search));
27}
28
29echo "Done";
30?>
31--EXPECTF--
32*** Testing array_key_exists() : usage variations ***
33
34-- Iteration 1 --
35Pass float as $key:
36
37Deprecated: Implicit conversion from float 1.23456789E-10 to int loses precision in %s on line %d
38bool(true)
39Cast float to int:
40bool(true)
41
42-- Iteration 1 --
43Pass float as $key:
44
45Deprecated: Implicit conversion from float 1.00000000000001 to int loses precision in %s on line %d
46bool(true)
47Cast float to int:
48bool(true)
49
50-- Iteration 1 --
51Pass float as $key:
52
53Deprecated: Implicit conversion from float 1.99999999999999 to int loses precision in %s on line %d
54bool(true)
55Cast float to int:
56bool(true)
57Done
58