1--TEST--
2Test array_key_exists() function : object functionality - different visibilities
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 * Pass array_key_exists() an object with private and protected properties
13 */
14
15echo "*** Testing array_key_exists() : object functionality ***\n";
16
17class myClass {
18	public $var1;
19	protected $var2;
20	private $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 = var2:\n";
36var_dump(array_key_exists('var2', $class1));
37echo "\$key = var3:\n";
38var_dump(array_key_exists('var3', $class1));
39echo "\$class1:\n";
40var_dump($class1);
41
42echo "\n-- Assign a value to \$class2->var3 --\n";
43$class2 = new myClass('x', 'y', 'z');
44echo "\$key = var3:\n";
45var_dump(array_key_exists('var3', $class2));
46echo "\$class2:\n";
47var_dump($class2);
48
49echo "Done";
50?>
51--EXPECTF--
52*** Testing array_key_exists() : object functionality ***
53
54-- Do not assign a value to $class1->var3 --
55$key = var1:
56bool(true)
57$key = var2:
58bool(false)
59$key = var3:
60bool(false)
61$class1:
62object(myClass)#1 (3) {
63  ["var1"]=>
64  string(1) "a"
65  ["var2":protected]=>
66  string(1) "b"
67  ["var3":"myClass":private]=>
68  NULL
69}
70
71-- Assign a value to $class2->var3 --
72$key = var3:
73bool(false)
74$class2:
75object(myClass)#2 (3) {
76  ["var1"]=>
77  string(1) "x"
78  ["var2":protected]=>
79  string(1) "y"
80  ["var3":"myClass":private]=>
81  string(1) "z"
82}
83Done
84