Annotation of embedaddon/php/ext/standard/tests/array/array_key_exists_variation3.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test array_key_exists() function : usage variations - floats and casting to ints
! 3: --FILE--
! 4: <?php
! 5: /* Prototype : bool array_key_exists(mixed $key, array $search)
! 6: * Description: Checks if the given key or index exists in the array
! 7: * Source code: ext/standard/array.c
! 8: * Alias to functions: key_exists
! 9: */
! 10:
! 11: /*
! 12: * Pass floats as $key argument, then cast float values
! 13: * to integers and pass as $key argument
! 14: */
! 15:
! 16: echo "*** Testing array_key_exists() : usage variations ***\n";
! 17:
! 18: $keys = array(1.2345678900E-10, 1.00000000000001, 1.99999999999999);
! 19:
! 20: $search = array ('zero', 'one', 'two');
! 21:
! 22: $iterator = 1;
! 23: foreach($keys as $key) {
! 24: echo "\n-- Iteration $iterator --\n";
! 25: echo "Pass float as \$key:\n";
! 26: var_dump(array_key_exists($key, $search));
! 27: echo "Cast float to int:\n";
! 28: var_dump(array_key_exists((int)$key, $search));
! 29: }
! 30:
! 31: echo "Done";
! 32: ?>
! 33:
! 34: --EXPECTF--
! 35: *** Testing array_key_exists() : usage variations ***
! 36:
! 37: -- Iteration 1 --
! 38: Pass float as $key:
! 39:
! 40: Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d
! 41: bool(false)
! 42: Cast float to int:
! 43: bool(true)
! 44:
! 45: -- Iteration 1 --
! 46: Pass float as $key:
! 47:
! 48: Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d
! 49: bool(false)
! 50: Cast float to int:
! 51: bool(true)
! 52:
! 53: -- Iteration 1 --
! 54: Pass float as $key:
! 55:
! 56: Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d
! 57: bool(false)
! 58: Cast float to int:
! 59: bool(true)
! 60: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>