key_exists_variation2.phpt 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. --TEST--
  2. Test function key_exists() by calling it with its expected arguments
  3. --CREDITS--
  4. Francesco Fullone ff@ideato.it
  5. #PHPTestFest Cesena Italia on 2009-06-20
  6. --FILE--
  7. <?php
  8. echo "*** test key_exists() by using mixed type of arrays ***\n";
  9. // there is not a index = 0 element
  10. $a = array(1 => 'bar', 'foo' => 'baz');
  11. var_dump(key_exists(0, $a));
  12. echo "integer\n";
  13. // 1 has index = 0
  14. $b = array(1, 'foo' => 'baz');
  15. var_dump(key_exists(0, $b));
  16. // 42 has index = 0, netherless its position is the latest
  17. $c = array('foo' => 'baz', 42);
  18. var_dump(key_exists(0, $c));
  19. echo "string\n";
  20. // 'bar' has index = 0, netherless it is a string
  21. $d = array('bar', 'foo' => 'baz');
  22. var_dump(key_exists(0, $d));
  23. // 'baz' has index = 0, netherless its position is the latest
  24. $e = array('foo' => 'baz', 'baz');
  25. var_dump(key_exists(0, $e));
  26. echo "obj\n";
  27. class ObjectA
  28. {
  29. public $foo = 'bar';
  30. }
  31. $obj = new ObjectA();
  32. // object has index = 0, netherless its position is the latest
  33. $f = array('foo' => 'baz', $obj);
  34. var_dump(key_exists(0, $f));
  35. // object has index = 0, netherless its position is the first
  36. $g = array($obj, 'foo' => 'baz');
  37. var_dump(key_exists(0, $g));
  38. echo "stream resource\n";
  39. // stream resource has index = 0, netherless its position is the first
  40. $st = fopen('php://memory', '+r');
  41. $h = array($st, 'foo' => 'baz');
  42. var_dump(key_exists(0, $h));
  43. // stream resource has index = 0, netherless its position is the latest
  44. $i = array('foo' => 'baz', $st);
  45. var_dump(key_exists(0, $i));
  46. --EXPECTF--
  47. *** test key_exists() by using mixed type of arrays ***
  48. bool(false)
  49. integer
  50. bool(true)
  51. bool(true)
  52. string
  53. bool(true)
  54. bool(true)
  55. obj
  56. bool(true)
  57. bool(true)
  58. stream resource
  59. bool(true)
  60. bool(true)