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:
54
55Deprecated: array_key_exists(): Using array_key_exists() on objects is deprecated. Use isset() or property_exists() instead in %s on line %d
56bool(true)
57$key = var3:
58
59Deprecated: array_key_exists(): Using array_key_exists() on objects is deprecated. Use isset() or property_exists() instead in %s on line %d
60bool(true)
61$class1:
62object(myClass)#1 (3) {
63  ["var1"]=>
64  string(1) "a"
65  ["var2"]=>
66  string(1) "b"
67  ["var3"]=>
68  NULL
69}
70
71-- Assign a value to $class2->var3 --
72$key = var3:
73
74Deprecated: array_key_exists(): Using array_key_exists() on objects is deprecated. Use isset() or property_exists() instead in %s on line %d
75bool(true)
76$class2:
77object(myClass)#2 (3) {
78  ["var1"]=>
79  string(1) "x"
80  ["var2"]=>
81  string(1) "y"
82  ["var3"]=>
83  string(1) "z"
84}
85Done
86