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