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