1--TEST-- 2Test array_key_exists() function : object functionality 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 * Test basic functionality of array_key_exists() with objects 13 */ 14 15echo "*** Testing array_key_exists() : object functionality ***\n"; 16 17class myClass { 18 var $var1; 19 var $var2; 20 var $var3; 21 22 function __construct($a, $b, $c = null) { 23 $this->var1 = $a; 24 $this->var2 = $b; 25 if (!is_null($c)) { 26 $this->var3 = $c; 27 } 28 } 29} 30 31echo "\n-- Do not assign a value to \$class1->var3 --\n"; 32$class1 = new myClass ('a', 'b'); 33echo "\$key = var1:\n"; 34var_dump(array_key_exists('var1', $class1)); 35echo "\$key = var3:\n"; 36var_dump(array_key_exists('var3', $class1)); 37echo "\$class1:\n"; 38var_dump($class1); 39 40echo "\n-- Assign a value to \$class2->var3 --\n"; 41$class2 = new myClass('x', 'y', 'z'); 42echo "\$key = var3:\n"; 43var_dump(array_key_exists('var3', $class2)); 44echo "\$class2:\n"; 45var_dump($class2); 46 47echo "Done"; 48?> 49 50--EXPECTF-- 51*** Testing array_key_exists() : object functionality *** 52 53-- Do not assign a value to $class1->var3 -- 54$key = var1: 55bool(true) 56$key = var3: 57bool(true) 58$class1: 59object(myClass)#1 (3) { 60 [%b|u%"var1"]=> 61 %unicode|string%(1) "a" 62 [%b|u%"var2"]=> 63 %unicode|string%(1) "b" 64 [%b|u%"var3"]=> 65 NULL 66} 67 68-- Assign a value to $class2->var3 -- 69$key = var3: 70bool(true) 71$class2: 72object(myClass)#2 (3) { 73 [%b|u%"var1"]=> 74 %unicode|string%(1) "x" 75 [%b|u%"var2"]=> 76 %unicode|string%(1) "y" 77 [%b|u%"var3"]=> 78 %unicode|string%(1) "z" 79} 80Done 81