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--EXPECTF-- 50*** Testing array_key_exists() : object functionality *** 51 52-- Do not assign a value to $class1->var3 -- 53$key = var1: 54bool(true) 55$key = var3: 56bool(true) 57$class1: 58object(myClass)#1 (3) { 59 [%b|u%"var1"]=> 60 %unicode|string%(1) "a" 61 [%b|u%"var2"]=> 62 %unicode|string%(1) "b" 63 [%b|u%"var3"]=> 64 NULL 65} 66 67-- Assign a value to $class2->var3 -- 68$key = var3: 69bool(true) 70$class2: 71object(myClass)#2 (3) { 72 [%b|u%"var1"]=> 73 %unicode|string%(1) "x" 74 [%b|u%"var2"]=> 75 %unicode|string%(1) "y" 76 [%b|u%"var3"]=> 77 %unicode|string%(1) "z" 78} 79Done 80