1--TEST--
2Implicit object instantiation when accessing properties of non-object.
3--FILE--
4<?php
5class C {
6	// These values get implicitly converted to objects
7	public $boolFalse = false;
8	public $emptyString = '';
9	public $null = null;
10
11	// These values do not get implicitly converted to objects
12	public $boolTrue = true;
13	public $nonEmptyString = 'hello';
14	public $intZero = 0;
15}
16
17$c = new C;
18foreach($c as $name => $value) {
19	echo "\n\n---( \$c->$name )---";
20	echo "\n  --> Attempting implicit conversion to object using increment...\n";
21	$c->$name->prop++;
22	$c->$name = $value; // reset value in case implicit conversion was successful
23
24	echo "\n  --> Attempting implicit conversion to object using assignment...\n";
25	$c->$name->prop = "Implicit instantiation!";
26	$c->$name = $value; // reset value in case implicit conversion was successful
27
28	echo "\n  --> Attempting implicit conversion to object using combined assignment...\n";
29	$c->$name->prop .= " Implicit instantiation!";
30}
31
32echo "\n\n\n --> Resulting object:";
33var_dump($c);
34
35?>
36--EXPECTF--
37
38
39---( $c->boolFalse )---
40  --> Attempting implicit conversion to object using increment...
41
42Warning: Creating default object from empty value in %s on line 18
43
44Notice: Undefined property: stdClass::$prop in %s on line 18
45
46  --> Attempting implicit conversion to object using assignment...
47
48Warning: Creating default object from empty value in %s on line 22
49
50  --> Attempting implicit conversion to object using combined assignment...
51
52Warning: Creating default object from empty value in %s on line 26
53
54Notice: Undefined property: stdClass::$prop in %s on line 26
55
56
57---( $c->emptyString )---
58  --> Attempting implicit conversion to object using increment...
59
60Warning: Creating default object from empty value in %s on line 18
61
62Notice: Undefined property: stdClass::$prop in %s on line 18
63
64  --> Attempting implicit conversion to object using assignment...
65
66Warning: Creating default object from empty value in %s on line 22
67
68  --> Attempting implicit conversion to object using combined assignment...
69
70Warning: Creating default object from empty value in %s on line 26
71
72Notice: Undefined property: stdClass::$prop in %s on line 26
73
74
75---( $c->null )---
76  --> Attempting implicit conversion to object using increment...
77
78Warning: Creating default object from empty value in %s on line 18
79
80Notice: Undefined property: stdClass::$prop in %s on line 18
81
82  --> Attempting implicit conversion to object using assignment...
83
84Warning: Creating default object from empty value in %s on line 22
85
86  --> Attempting implicit conversion to object using combined assignment...
87
88Warning: Creating default object from empty value in %s on line 26
89
90Notice: Undefined property: stdClass::$prop in %s on line 26
91
92
93---( $c->boolTrue )---
94  --> Attempting implicit conversion to object using increment...
95
96Warning: Attempt to %s property of non-object in %s on line 18
97
98  --> Attempting implicit conversion to object using assignment...
99
100Warning: Attempt to assign property of non-object in %s on line 22
101
102  --> Attempting implicit conversion to object using combined assignment...
103
104Warning: Attempt to assign property of non-object in %s on line 26
105
106
107---( $c->nonEmptyString )---
108  --> Attempting implicit conversion to object using increment...
109
110Warning: Attempt to %s property of non-object in %s on line 18
111
112  --> Attempting implicit conversion to object using assignment...
113
114Warning: Attempt to assign property of non-object in %s on line 22
115
116  --> Attempting implicit conversion to object using combined assignment...
117
118Warning: Attempt to assign property of non-object in %s on line 26
119
120
121---( $c->intZero )---
122  --> Attempting implicit conversion to object using increment...
123
124Warning: Attempt to %s property of non-object in %s on line 18
125
126  --> Attempting implicit conversion to object using assignment...
127
128Warning: Attempt to assign property of non-object in %s on line 22
129
130  --> Attempting implicit conversion to object using combined assignment...
131
132Warning: Attempt to assign property of non-object in %s on line 26
133
134
135
136 --> Resulting object:object(C)#%d (6) {
137  [%u|b%"boolFalse"]=>
138  object(stdClass)#%d (1) {
139    [%u|b%"prop"]=>
140    %unicode|string%(24) " Implicit instantiation!"
141  }
142  [%u|b%"emptyString"]=>
143  object(stdClass)#%d (1) {
144    [%u|b%"prop"]=>
145    %unicode|string%(24) " Implicit instantiation!"
146  }
147  [%u|b%"null"]=>
148  object(stdClass)#%d (1) {
149    [%u|b%"prop"]=>
150    %unicode|string%(24) " Implicit instantiation!"
151  }
152  [%u|b%"boolTrue"]=>
153  bool(true)
154  [%u|b%"nonEmptyString"]=>
155  %unicode|string%(5) "hello"
156  [%u|b%"intZero"]=>
157  int(0)
158}
159