Annotation of embedaddon/php/tests/classes/tostring_001.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: ZE2 __toString()
! 3: --FILE--
! 4: <?php
! 5:
! 6: function my_error_handler($errno, $errstr, $errfile, $errline) {
! 7: var_dump($errstr);
! 8: }
! 9:
! 10: set_error_handler('my_error_handler');
! 11:
! 12: class test1
! 13: {
! 14: }
! 15:
! 16: class test2
! 17: {
! 18: function __toString()
! 19: {
! 20: echo __METHOD__ . "()\n";
! 21: return "Converted\n";
! 22: }
! 23: }
! 24:
! 25: class test3
! 26: {
! 27: function __toString()
! 28: {
! 29: echo __METHOD__ . "()\n";
! 30: return 42;
! 31: }
! 32: }
! 33: echo "====test1====\n";
! 34: $o = new test1;
! 35: print_r($o);
! 36: var_dump((string)$o);
! 37: var_dump($o);
! 38:
! 39: echo "====test2====\n";
! 40: $o = new test2;
! 41: print_r($o);
! 42: print $o;
! 43: var_dump($o);
! 44: echo "====test3====\n";
! 45: echo $o;
! 46:
! 47: echo "====test4====\n";
! 48: echo "string:".$o;
! 49:
! 50: echo "====test5====\n";
! 51: echo 1 . $o;
! 52: echo 1 , $o;
! 53:
! 54: echo "====test6====\n";
! 55: echo $o . $o;
! 56: echo $o , $o;
! 57:
! 58: echo "====test7====\n";
! 59: $ar = array();
! 60: $ar[$o->__toString()] = "ERROR";
! 61: echo $ar[$o];
! 62:
! 63: echo "====test8====\n";
! 64: var_dump(trim($o));
! 65: var_dump(trim((string)$o));
! 66:
! 67: echo "====test9====\n";
! 68: echo sprintf("%s", $o);
! 69:
! 70: echo "====test10====\n";
! 71: $o = new test3;
! 72: var_dump($o);
! 73: echo $o;
! 74:
! 75: ?>
! 76: ====DONE====
! 77: --EXPECTF--
! 78: ====test1====
! 79: test1 Object
! 80: (
! 81: )
! 82: string(54) "Object of class test1 could not be converted to string"
! 83: string(0) ""
! 84: object(test1)#%d (0) {
! 85: }
! 86: ====test2====
! 87: test2 Object
! 88: (
! 89: )
! 90: test2::__toString()
! 91: Converted
! 92: object(test2)#%d (0) {
! 93: }
! 94: ====test3====
! 95: test2::__toString()
! 96: Converted
! 97: ====test4====
! 98: test2::__toString()
! 99: string:Converted
! 100: ====test5====
! 101: test2::__toString()
! 102: 1Converted
! 103: 1test2::__toString()
! 104: Converted
! 105: ====test6====
! 106: test2::__toString()
! 107: test2::__toString()
! 108: Converted
! 109: Converted
! 110: test2::__toString()
! 111: Converted
! 112: test2::__toString()
! 113: Converted
! 114: ====test7====
! 115: test2::__toString()
! 116: string(19) "Illegal offset type"
! 117: ====test8====
! 118: test2::__toString()
! 119: string(9) "Converted"
! 120: test2::__toString()
! 121: string(9) "Converted"
! 122: ====test9====
! 123: test2::__toString()
! 124: Converted
! 125: ====test10====
! 126: object(test3)#%d (0) {
! 127: }
! 128: test3::__toString()
! 129: string(53) "Method test3::__toString() must return a string value"
! 130: ====DONE====
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>