Annotation of embedaddon/php/ext/standard/tests/class_object/is_a.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: is_a and is_subclass_of behaviour (with and without autoload)
! 3: --SKIPIF--
! 4: <?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?>
! 5: --FILE--
! 6: <?php
! 7:
! 8: interface if_a {
! 9: function f_a();
! 10: }
! 11:
! 12: interface if_b extends if_a {
! 13: function f_b();
! 14: }
! 15:
! 16: class base {
! 17: function _is_a($sub) {
! 18:
! 19: echo "\n>>> With Defined class\n";
! 20: echo str_pad('is_a( OBJECT:'.get_class($this).', '.$sub.') = ', 60) . (is_a($this, $sub) ? 'yes' : 'no')."\n";
! 21: echo str_pad('is_a( STRING:'.get_class($this).', '.$sub.') = ', 60). (is_a(get_class($this), $sub) ? 'yes' : 'no')."\n";
! 22: echo str_pad('is_a( STRING:'.get_class($this).', '.$sub.', true) = ', 60). (is_a(get_class($this), $sub, true) ? 'yes' : 'no')."\n";
! 23: echo str_pad('is_subclass_of( OBJECT:'.get_class($this).', '.$sub.') = ', 60). (is_subclass_of($this, $sub) ? 'yes' : 'no')."\n";
! 24: echo str_pad('is_subclass_of( STRING:'.get_class($this).', '.$sub.') = ', 60). (is_subclass_of(get_class($this), $sub) ? 'yes' : 'no')."\n";
! 25: echo str_pad('is_subclass_of( STRING:'.get_class($this).', '.$sub.',false) = ', 60). (is_subclass_of(get_class($this), $sub , false) ? 'yes' : 'no')."\n";
! 26:
! 27: // with autoload options..
! 28: echo ">>> With Undefined\n";
! 29: echo str_pad('is_a( STRING:undefB, '.$sub.',true) = ', 60). (is_a('undefB', $sub, true) ? 'yes' : 'no')."\n";
! 30: echo str_pad('is_a( STRING:undefB, '.$sub.') = ', 60). (is_a('undefB', $sub) ? 'yes' : 'no')."\n";
! 31: echo str_pad('is_subclass_of( STRING:undefB, '.$sub.',false) = ', 60). (is_subclass_of('undefB', $sub, false) ? 'yes' : 'no')."\n";
! 32: echo str_pad('is_subclass_of( STRING:undefB, '.$sub.') = ', 60). (is_subclass_of('undefB', $sub) ? 'yes' : 'no')."\n";
! 33: }
! 34: function test() {
! 35: echo $this->_is_a('base');
! 36: echo $this->_is_a('derived_a');
! 37: echo $this->_is_a('if_a');
! 38: echo $this->_is_a('undefA');
! 39: echo "\n";
! 40: }
! 41: }
! 42:
! 43: class derived_a extends base implements if_a {
! 44: function f_a() {}
! 45: }
! 46:
! 47: class derived_b extends base implements if_a, if_b {
! 48: function f_a() {}
! 49: function f_b() {}
! 50: }
! 51:
! 52: class derived_c extends derived_a implements if_b {
! 53: function f_b() {}
! 54: }
! 55:
! 56: class derived_d extends derived_c {
! 57: }
! 58:
! 59: $t = new base();
! 60: $t->test();
! 61:
! 62: $t = new derived_a();
! 63: $t->test();
! 64:
! 65: eval('
! 66: function __autoload($name)
! 67: {
! 68: echo ">>>> In __autoload: ";
! 69: var_dump($name);
! 70: }
! 71: ');
! 72:
! 73: echo "NOW WITH AUTOLOAD\n\n";
! 74:
! 75: $t = new base();
! 76: $t->test();
! 77:
! 78: $t = new derived_a();
! 79: $t->test();
! 80:
! 81: $t = new derived_b();
! 82: $t->test();
! 83:
! 84:
! 85:
! 86:
! 87:
! 88: ?>
! 89: --EXPECTF--
! 90: >>> With Defined class
! 91: is_a( OBJECT:base, base) = yes
! 92: is_a( STRING:base, base) = no
! 93: is_a( STRING:base, base, true) = yes
! 94: is_subclass_of( OBJECT:base, base) = no
! 95: is_subclass_of( STRING:base, base) = no
! 96: is_subclass_of( STRING:base, base,false) = no
! 97: >>> With Undefined
! 98: is_a( STRING:undefB, base,true) = no
! 99: is_a( STRING:undefB, base) = no
! 100: is_subclass_of( STRING:undefB, base,false) = no
! 101: is_subclass_of( STRING:undefB, base) = no
! 102:
! 103: >>> With Defined class
! 104: is_a( OBJECT:base, derived_a) = no
! 105: is_a( STRING:base, derived_a) = no
! 106: is_a( STRING:base, derived_a, true) = no
! 107: is_subclass_of( OBJECT:base, derived_a) = no
! 108: is_subclass_of( STRING:base, derived_a) = no
! 109: is_subclass_of( STRING:base, derived_a,false) = no
! 110: >>> With Undefined
! 111: is_a( STRING:undefB, derived_a,true) = no
! 112: is_a( STRING:undefB, derived_a) = no
! 113: is_subclass_of( STRING:undefB, derived_a,false) = no
! 114: is_subclass_of( STRING:undefB, derived_a) = no
! 115:
! 116: >>> With Defined class
! 117: is_a( OBJECT:base, if_a) = no
! 118: is_a( STRING:base, if_a) = no
! 119: is_a( STRING:base, if_a, true) = no
! 120: is_subclass_of( OBJECT:base, if_a) = no
! 121: is_subclass_of( STRING:base, if_a) = no
! 122: is_subclass_of( STRING:base, if_a,false) = no
! 123: >>> With Undefined
! 124: is_a( STRING:undefB, if_a,true) = no
! 125: is_a( STRING:undefB, if_a) = no
! 126: is_subclass_of( STRING:undefB, if_a,false) = no
! 127: is_subclass_of( STRING:undefB, if_a) = no
! 128:
! 129: >>> With Defined class
! 130: is_a( OBJECT:base, undefA) = no
! 131: is_a( STRING:base, undefA) = no
! 132: is_a( STRING:base, undefA, true) = no
! 133: is_subclass_of( OBJECT:base, undefA) = no
! 134: is_subclass_of( STRING:base, undefA) = no
! 135: is_subclass_of( STRING:base, undefA,false) = no
! 136: >>> With Undefined
! 137: is_a( STRING:undefB, undefA,true) = no
! 138: is_a( STRING:undefB, undefA) = no
! 139: is_subclass_of( STRING:undefB, undefA,false) = no
! 140: is_subclass_of( STRING:undefB, undefA) = no
! 141:
! 142:
! 143: >>> With Defined class
! 144: is_a( OBJECT:derived_a, base) = yes
! 145: is_a( STRING:derived_a, base) = no
! 146: is_a( STRING:derived_a, base, true) = yes
! 147: is_subclass_of( OBJECT:derived_a, base) = yes
! 148: is_subclass_of( STRING:derived_a, base) = yes
! 149: is_subclass_of( STRING:derived_a, base,false) = no
! 150: >>> With Undefined
! 151: is_a( STRING:undefB, base,true) = no
! 152: is_a( STRING:undefB, base) = no
! 153: is_subclass_of( STRING:undefB, base,false) = no
! 154: is_subclass_of( STRING:undefB, base) = no
! 155:
! 156: >>> With Defined class
! 157: is_a( OBJECT:derived_a, derived_a) = yes
! 158: is_a( STRING:derived_a, derived_a) = no
! 159: is_a( STRING:derived_a, derived_a, true) = yes
! 160: is_subclass_of( OBJECT:derived_a, derived_a) = no
! 161: is_subclass_of( STRING:derived_a, derived_a) = no
! 162: is_subclass_of( STRING:derived_a, derived_a,false) = no
! 163: >>> With Undefined
! 164: is_a( STRING:undefB, derived_a,true) = no
! 165: is_a( STRING:undefB, derived_a) = no
! 166: is_subclass_of( STRING:undefB, derived_a,false) = no
! 167: is_subclass_of( STRING:undefB, derived_a) = no
! 168:
! 169: >>> With Defined class
! 170: is_a( OBJECT:derived_a, if_a) = yes
! 171: is_a( STRING:derived_a, if_a) = no
! 172: is_a( STRING:derived_a, if_a, true) = yes
! 173: is_subclass_of( OBJECT:derived_a, if_a) = yes
! 174: is_subclass_of( STRING:derived_a, if_a) = yes
! 175: is_subclass_of( STRING:derived_a, if_a,false) = no
! 176: >>> With Undefined
! 177: is_a( STRING:undefB, if_a,true) = no
! 178: is_a( STRING:undefB, if_a) = no
! 179: is_subclass_of( STRING:undefB, if_a,false) = no
! 180: is_subclass_of( STRING:undefB, if_a) = no
! 181:
! 182: >>> With Defined class
! 183: is_a( OBJECT:derived_a, undefA) = no
! 184: is_a( STRING:derived_a, undefA) = no
! 185: is_a( STRING:derived_a, undefA, true) = no
! 186: is_subclass_of( OBJECT:derived_a, undefA) = no
! 187: is_subclass_of( STRING:derived_a, undefA) = no
! 188: is_subclass_of( STRING:derived_a, undefA,false) = no
! 189: >>> With Undefined
! 190: is_a( STRING:undefB, undefA,true) = no
! 191: is_a( STRING:undefB, undefA) = no
! 192: is_subclass_of( STRING:undefB, undefA,false) = no
! 193: is_subclass_of( STRING:undefB, undefA) = no
! 194:
! 195: NOW WITH AUTOLOAD
! 196:
! 197:
! 198: >>> With Defined class
! 199: is_a( OBJECT:base, base) = yes
! 200: is_a( STRING:base, base) = no
! 201: is_a( STRING:base, base, true) = yes
! 202: is_subclass_of( OBJECT:base, base) = no
! 203: is_subclass_of( STRING:base, base) = no
! 204: is_subclass_of( STRING:base, base,false) = no
! 205: >>> With Undefined
! 206: >>>> In __autoload: string(6) "undefB"
! 207: is_a( STRING:undefB, base,true) = no
! 208: is_a( STRING:undefB, base) = no
! 209: is_subclass_of( STRING:undefB, base,false) = no
! 210: >>>> In __autoload: string(6) "undefB"
! 211: is_subclass_of( STRING:undefB, base) = no
! 212:
! 213: >>> With Defined class
! 214: is_a( OBJECT:base, derived_a) = no
! 215: is_a( STRING:base, derived_a) = no
! 216: is_a( STRING:base, derived_a, true) = no
! 217: is_subclass_of( OBJECT:base, derived_a) = no
! 218: is_subclass_of( STRING:base, derived_a) = no
! 219: is_subclass_of( STRING:base, derived_a,false) = no
! 220: >>> With Undefined
! 221: >>>> In __autoload: string(6) "undefB"
! 222: is_a( STRING:undefB, derived_a,true) = no
! 223: is_a( STRING:undefB, derived_a) = no
! 224: is_subclass_of( STRING:undefB, derived_a,false) = no
! 225: >>>> In __autoload: string(6) "undefB"
! 226: is_subclass_of( STRING:undefB, derived_a) = no
! 227:
! 228: >>> With Defined class
! 229: is_a( OBJECT:base, if_a) = no
! 230: is_a( STRING:base, if_a) = no
! 231: is_a( STRING:base, if_a, true) = no
! 232: is_subclass_of( OBJECT:base, if_a) = no
! 233: is_subclass_of( STRING:base, if_a) = no
! 234: is_subclass_of( STRING:base, if_a,false) = no
! 235: >>> With Undefined
! 236: >>>> In __autoload: string(6) "undefB"
! 237: is_a( STRING:undefB, if_a,true) = no
! 238: is_a( STRING:undefB, if_a) = no
! 239: is_subclass_of( STRING:undefB, if_a,false) = no
! 240: >>>> In __autoload: string(6) "undefB"
! 241: is_subclass_of( STRING:undefB, if_a) = no
! 242:
! 243: >>> With Defined class
! 244: is_a( OBJECT:base, undefA) = no
! 245: is_a( STRING:base, undefA) = no
! 246: is_a( STRING:base, undefA, true) = no
! 247: is_subclass_of( OBJECT:base, undefA) = no
! 248: is_subclass_of( STRING:base, undefA) = no
! 249: is_subclass_of( STRING:base, undefA,false) = no
! 250: >>> With Undefined
! 251: >>>> In __autoload: string(6) "undefB"
! 252: is_a( STRING:undefB, undefA,true) = no
! 253: is_a( STRING:undefB, undefA) = no
! 254: is_subclass_of( STRING:undefB, undefA,false) = no
! 255: >>>> In __autoload: string(6) "undefB"
! 256: is_subclass_of( STRING:undefB, undefA) = no
! 257:
! 258:
! 259: >>> With Defined class
! 260: is_a( OBJECT:derived_a, base) = yes
! 261: is_a( STRING:derived_a, base) = no
! 262: is_a( STRING:derived_a, base, true) = yes
! 263: is_subclass_of( OBJECT:derived_a, base) = yes
! 264: is_subclass_of( STRING:derived_a, base) = yes
! 265: is_subclass_of( STRING:derived_a, base,false) = no
! 266: >>> With Undefined
! 267: >>>> In __autoload: string(6) "undefB"
! 268: is_a( STRING:undefB, base,true) = no
! 269: is_a( STRING:undefB, base) = no
! 270: is_subclass_of( STRING:undefB, base,false) = no
! 271: >>>> In __autoload: string(6) "undefB"
! 272: is_subclass_of( STRING:undefB, base) = no
! 273:
! 274: >>> With Defined class
! 275: is_a( OBJECT:derived_a, derived_a) = yes
! 276: is_a( STRING:derived_a, derived_a) = no
! 277: is_a( STRING:derived_a, derived_a, true) = yes
! 278: is_subclass_of( OBJECT:derived_a, derived_a) = no
! 279: is_subclass_of( STRING:derived_a, derived_a) = no
! 280: is_subclass_of( STRING:derived_a, derived_a,false) = no
! 281: >>> With Undefined
! 282: >>>> In __autoload: string(6) "undefB"
! 283: is_a( STRING:undefB, derived_a,true) = no
! 284: is_a( STRING:undefB, derived_a) = no
! 285: is_subclass_of( STRING:undefB, derived_a,false) = no
! 286: >>>> In __autoload: string(6) "undefB"
! 287: is_subclass_of( STRING:undefB, derived_a) = no
! 288:
! 289: >>> With Defined class
! 290: is_a( OBJECT:derived_a, if_a) = yes
! 291: is_a( STRING:derived_a, if_a) = no
! 292: is_a( STRING:derived_a, if_a, true) = yes
! 293: is_subclass_of( OBJECT:derived_a, if_a) = yes
! 294: is_subclass_of( STRING:derived_a, if_a) = yes
! 295: is_subclass_of( STRING:derived_a, if_a,false) = no
! 296: >>> With Undefined
! 297: >>>> In __autoload: string(6) "undefB"
! 298: is_a( STRING:undefB, if_a,true) = no
! 299: is_a( STRING:undefB, if_a) = no
! 300: is_subclass_of( STRING:undefB, if_a,false) = no
! 301: >>>> In __autoload: string(6) "undefB"
! 302: is_subclass_of( STRING:undefB, if_a) = no
! 303:
! 304: >>> With Defined class
! 305: is_a( OBJECT:derived_a, undefA) = no
! 306: is_a( STRING:derived_a, undefA) = no
! 307: is_a( STRING:derived_a, undefA, true) = no
! 308: is_subclass_of( OBJECT:derived_a, undefA) = no
! 309: is_subclass_of( STRING:derived_a, undefA) = no
! 310: is_subclass_of( STRING:derived_a, undefA,false) = no
! 311: >>> With Undefined
! 312: >>>> In __autoload: string(6) "undefB"
! 313: is_a( STRING:undefB, undefA,true) = no
! 314: is_a( STRING:undefB, undefA) = no
! 315: is_subclass_of( STRING:undefB, undefA,false) = no
! 316: >>>> In __autoload: string(6) "undefB"
! 317: is_subclass_of( STRING:undefB, undefA) = no
! 318:
! 319:
! 320: >>> With Defined class
! 321: is_a( OBJECT:derived_b, base) = yes
! 322: is_a( STRING:derived_b, base) = no
! 323: is_a( STRING:derived_b, base, true) = yes
! 324: is_subclass_of( OBJECT:derived_b, base) = yes
! 325: is_subclass_of( STRING:derived_b, base) = yes
! 326: is_subclass_of( STRING:derived_b, base,false) = no
! 327: >>> With Undefined
! 328: >>>> In __autoload: string(6) "undefB"
! 329: is_a( STRING:undefB, base,true) = no
! 330: is_a( STRING:undefB, base) = no
! 331: is_subclass_of( STRING:undefB, base,false) = no
! 332: >>>> In __autoload: string(6) "undefB"
! 333: is_subclass_of( STRING:undefB, base) = no
! 334:
! 335: >>> With Defined class
! 336: is_a( OBJECT:derived_b, derived_a) = no
! 337: is_a( STRING:derived_b, derived_a) = no
! 338: is_a( STRING:derived_b, derived_a, true) = no
! 339: is_subclass_of( OBJECT:derived_b, derived_a) = no
! 340: is_subclass_of( STRING:derived_b, derived_a) = no
! 341: is_subclass_of( STRING:derived_b, derived_a,false) = no
! 342: >>> With Undefined
! 343: >>>> In __autoload: string(6) "undefB"
! 344: is_a( STRING:undefB, derived_a,true) = no
! 345: is_a( STRING:undefB, derived_a) = no
! 346: is_subclass_of( STRING:undefB, derived_a,false) = no
! 347: >>>> In __autoload: string(6) "undefB"
! 348: is_subclass_of( STRING:undefB, derived_a) = no
! 349:
! 350: >>> With Defined class
! 351: is_a( OBJECT:derived_b, if_a) = yes
! 352: is_a( STRING:derived_b, if_a) = no
! 353: is_a( STRING:derived_b, if_a, true) = yes
! 354: is_subclass_of( OBJECT:derived_b, if_a) = yes
! 355: is_subclass_of( STRING:derived_b, if_a) = yes
! 356: is_subclass_of( STRING:derived_b, if_a,false) = no
! 357: >>> With Undefined
! 358: >>>> In __autoload: string(6) "undefB"
! 359: is_a( STRING:undefB, if_a,true) = no
! 360: is_a( STRING:undefB, if_a) = no
! 361: is_subclass_of( STRING:undefB, if_a,false) = no
! 362: >>>> In __autoload: string(6) "undefB"
! 363: is_subclass_of( STRING:undefB, if_a) = no
! 364:
! 365: >>> With Defined class
! 366: is_a( OBJECT:derived_b, undefA) = no
! 367: is_a( STRING:derived_b, undefA) = no
! 368: is_a( STRING:derived_b, undefA, true) = no
! 369: is_subclass_of( OBJECT:derived_b, undefA) = no
! 370: is_subclass_of( STRING:derived_b, undefA) = no
! 371: is_subclass_of( STRING:derived_b, undefA,false) = no
! 372: >>> With Undefined
! 373: >>>> In __autoload: string(6) "undefB"
! 374: is_a( STRING:undefB, undefA,true) = no
! 375: is_a( STRING:undefB, undefA) = no
! 376: is_subclass_of( STRING:undefB, undefA,false) = no
! 377: >>>> In __autoload: string(6) "undefB"
! 378: is_subclass_of( STRING:undefB, undefA) = no
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>