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---( $c->boolFalse )--- 38 --> Attempting implicit conversion to object using increment... 39 40Warning: Creating default object from empty value in %s on line 18 41 42Notice: Undefined property: stdClass::$prop in %s on line 18 43 44 --> Attempting implicit conversion to object using assignment... 45 46Warning: Creating default object from empty value in %s on line 22 47 48 --> Attempting implicit conversion to object using combined assignment... 49 50Warning: Creating default object from empty value in %s on line 26 51 52Notice: Undefined property: stdClass::$prop in %s on line 26 53 54 55---( $c->emptyString )--- 56 --> Attempting implicit conversion to object using increment... 57 58Warning: Creating default object from empty value in %s on line 18 59 60Notice: Undefined property: stdClass::$prop in %s on line 18 61 62 --> Attempting implicit conversion to object using assignment... 63 64Warning: Creating default object from empty value in %s on line 22 65 66 --> Attempting implicit conversion to object using combined assignment... 67 68Warning: Creating default object from empty value in %s on line 26 69 70Notice: Undefined property: stdClass::$prop in %s on line 26 71 72 73---( $c->null )--- 74 --> Attempting implicit conversion to object using increment... 75 76Warning: Creating default object from empty value in %s on line 18 77 78Notice: Undefined property: stdClass::$prop in %s on line 18 79 80 --> Attempting implicit conversion to object using assignment... 81 82Warning: Creating default object from empty value in %s on line 22 83 84 --> Attempting implicit conversion to object using combined assignment... 85 86Warning: Creating default object from empty value in %s on line 26 87 88Notice: Undefined property: stdClass::$prop in %s on line 26 89 90 91---( $c->boolTrue )--- 92 --> Attempting implicit conversion to object using increment... 93 94Warning: Attempt to %s property 'prop' of non-object in %s on line 18 95 96 --> Attempting implicit conversion to object using assignment... 97 98Warning: Attempt to assign property 'prop' of non-object in %s on line 22 99 100 --> Attempting implicit conversion to object using combined assignment... 101 102Warning: Attempt to assign property 'prop' of non-object in %s on line 26 103 104 105---( $c->nonEmptyString )--- 106 --> Attempting implicit conversion to object using increment... 107 108Warning: Attempt to %s property 'prop' of non-object in %s on line 18 109 110 --> Attempting implicit conversion to object using assignment... 111 112Warning: Attempt to assign property 'prop' of non-object in %s on line 22 113 114 --> Attempting implicit conversion to object using combined assignment... 115 116Warning: Attempt to assign property 'prop' of non-object in %s on line 26 117 118 119---( $c->intZero )--- 120 --> Attempting implicit conversion to object using increment... 121 122Warning: Attempt to %s property 'prop' of non-object in %s on line 18 123 124 --> Attempting implicit conversion to object using assignment... 125 126Warning: Attempt to assign property 'prop' of non-object in %s on line 22 127 128 --> Attempting implicit conversion to object using combined assignment... 129 130Warning: Attempt to assign property 'prop' of non-object in %s on line 26 131 132 133 134 --> Resulting object:object(C)#%d (6) { 135 ["boolFalse"]=> 136 object(stdClass)#%d (1) { 137 ["prop"]=> 138 string(24) " Implicit instantiation!" 139 } 140 ["emptyString"]=> 141 object(stdClass)#%d (1) { 142 ["prop"]=> 143 string(24) " Implicit instantiation!" 144 } 145 ["null"]=> 146 object(stdClass)#%d (1) { 147 ["prop"]=> 148 string(24) " Implicit instantiation!" 149 } 150 ["boolTrue"]=> 151 bool(true) 152 ["nonEmptyString"]=> 153 string(5) "hello" 154 ["intZero"]=> 155 int(0) 156} 157