Annotation of embedaddon/php/tests/classes/implicit_instantiation_001.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Implicit object instantiation when accessing properties of non-object.
! 3: --FILE--
! 4: <?php
! 5: class 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;
! 18: foreach($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:
! 32: echo "\n\n\n --> Resulting object:";
! 33: var_dump($c);
! 34:
! 35: ?>
! 36: --EXPECTF--
! 37:
! 38:
! 39: ---( $c->boolFalse )---
! 40: --> Attempting implicit conversion to object using increment...
! 41:
! 42: Strict Standards: Creating default object from empty value in %s on line 18
! 43:
! 44: --> Attempting implicit conversion to object using assignment...
! 45:
! 46: Strict Standards: Creating default object from empty value in %s on line 22
! 47:
! 48: --> Attempting implicit conversion to object using combined assignment...
! 49:
! 50: Strict Standards: Creating default object from empty value in %s on line 26
! 51:
! 52:
! 53: ---( $c->emptyString )---
! 54: --> Attempting implicit conversion to object using increment...
! 55:
! 56: Strict Standards: Creating default object from empty value in %s on line 18
! 57:
! 58: --> Attempting implicit conversion to object using assignment...
! 59:
! 60: Strict Standards: Creating default object from empty value in %s on line 22
! 61:
! 62: --> Attempting implicit conversion to object using combined assignment...
! 63:
! 64: Strict Standards: Creating default object from empty value in %s on line 26
! 65:
! 66:
! 67: ---( $c->null )---
! 68: --> Attempting implicit conversion to object using increment...
! 69:
! 70: Strict Standards: Creating default object from empty value in %s on line 18
! 71:
! 72: --> Attempting implicit conversion to object using assignment...
! 73:
! 74: Strict Standards: Creating default object from empty value in %s on line 22
! 75:
! 76: --> Attempting implicit conversion to object using combined assignment...
! 77:
! 78: Strict Standards: Creating default object from empty value in %s on line 26
! 79:
! 80:
! 81: ---( $c->boolTrue )---
! 82: --> Attempting implicit conversion to object using increment...
! 83:
! 84: Warning: Attempt to %s property of non-object in %s on line 18
! 85:
! 86: --> Attempting implicit conversion to object using assignment...
! 87:
! 88: Warning: Attempt to assign property of non-object in %s on line 22
! 89:
! 90: --> Attempting implicit conversion to object using combined assignment...
! 91:
! 92: Warning: Attempt to assign property of non-object in %s on line 26
! 93:
! 94:
! 95: ---( $c->nonEmptyString )---
! 96: --> Attempting implicit conversion to object using increment...
! 97:
! 98: Warning: Attempt to %s property of non-object in %s on line 18
! 99:
! 100: --> Attempting implicit conversion to object using assignment...
! 101:
! 102: Warning: Attempt to assign property of non-object in %s on line 22
! 103:
! 104: --> Attempting implicit conversion to object using combined assignment...
! 105:
! 106: Warning: Attempt to assign property of non-object in %s on line 26
! 107:
! 108:
! 109: ---( $c->intZero )---
! 110: --> Attempting implicit conversion to object using increment...
! 111:
! 112: Warning: Attempt to %s property of non-object in %s on line 18
! 113:
! 114: --> Attempting implicit conversion to object using assignment...
! 115:
! 116: Warning: Attempt to assign property of non-object in %s on line 22
! 117:
! 118: --> Attempting implicit conversion to object using combined assignment...
! 119:
! 120: Warning: Attempt to assign property of non-object in %s on line 26
! 121:
! 122:
! 123:
! 124: --> Resulting object:object(C)#%d (6) {
! 125: [%u|b%"boolFalse"]=>
! 126: object(stdClass)#%d (1) {
! 127: [%u|b%"prop"]=>
! 128: %unicode|string%(24) " Implicit instantiation!"
! 129: }
! 130: [%u|b%"emptyString"]=>
! 131: object(stdClass)#%d (1) {
! 132: [%u|b%"prop"]=>
! 133: %unicode|string%(24) " Implicit instantiation!"
! 134: }
! 135: [%u|b%"null"]=>
! 136: object(stdClass)#%d (1) {
! 137: [%u|b%"prop"]=>
! 138: %unicode|string%(24) " Implicit instantiation!"
! 139: }
! 140: [%u|b%"boolTrue"]=>
! 141: bool(true)
! 142: [%u|b%"nonEmptyString"]=>
! 143: %unicode|string%(5) "hello"
! 144: [%u|b%"intZero"]=>
! 145: int(0)
! 146: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>