Annotation of embedaddon/php/ext/mbstring/tests/mb_strlen_variation1.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test mb_strlen() function : usage variations - Pass different data types as $str arg
! 3: --SKIPIF--
! 4: <?php
! 5: extension_loaded('mbstring') or die('skip');
! 6: function_exists('mb_strlen') or die("skip mb_strlen() is not available in this build");
! 7: ?>
! 8: --FILE--
! 9: <?php
! 10: /* Prototype : int mb_strlen(string $str [, string $encoding])
! 11: * Description: Get character numbers of a string
! 12: * Source code: ext/mbstring/mbstring.c
! 13: */
! 14:
! 15: /*
! 16: * Test mb_strlen by passing different data types as $str argument
! 17: */
! 18:
! 19: echo "*** Testing mb_strlen() : usage variations ***\n";
! 20:
! 21: // Initialise function arguments not being substituted
! 22: $encoding = 'utf-8';
! 23:
! 24: //get an unset variable
! 25: $unset_var = 10;
! 26: unset ($unset_var);
! 27:
! 28: // get a class
! 29: class classA
! 30: {
! 31: public function __toString() {
! 32: return b"Class A object";
! 33: }
! 34: }
! 35:
! 36: // heredoc string
! 37: $heredoc = b<<<EOT
! 38: hello world
! 39: EOT;
! 40:
! 41: // get a resource variable
! 42: $fp = fopen(__FILE__, "r");
! 43:
! 44: // unexpected values to be passed to $str argument
! 45: $inputs = array(
! 46:
! 47: // int data
! 48: /*1*/ 0,
! 49: 1,
! 50: 12345,
! 51: -2345,
! 52:
! 53: // float data
! 54: /*5*/ 10.5,
! 55: -10.5,
! 56: 12.3456789000e10,
! 57: 12.3456789000E-10,
! 58: .5,
! 59:
! 60: // null data
! 61: /*10*/ NULL,
! 62: null,
! 63:
! 64: // boolean data
! 65: /*12*/ true,
! 66: false,
! 67: TRUE,
! 68: FALSE,
! 69:
! 70: // empty data
! 71: /*16*/ "",
! 72: '',
! 73:
! 74: // string data
! 75: /*18*/ b"string",
! 76: b'string',
! 77: $heredoc,
! 78:
! 79: // object data
! 80: /*21*/ new classA(),
! 81:
! 82: // undefined data
! 83: /*22*/ @$undefined_var,
! 84:
! 85: // unset data
! 86: /*23*/ @$unset_var,
! 87:
! 88: // resource variable
! 89: /*24*/ $fp
! 90: );
! 91:
! 92: // loop through each element of $inputs to check the behavior of mb_strlen()
! 93: $iterator = 1;
! 94: foreach($inputs as $input) {
! 95: echo "\n-- Iteration $iterator --\n";
! 96: var_dump( mb_strlen($input, $encoding));
! 97: $iterator++;
! 98: };
! 99:
! 100: fclose($fp);
! 101:
! 102: echo "Done";
! 103: ?>
! 104: --EXPECTF--
! 105: *** Testing mb_strlen() : usage variations ***
! 106:
! 107: -- Iteration 1 --
! 108: int(1)
! 109:
! 110: -- Iteration 2 --
! 111: int(1)
! 112:
! 113: -- Iteration 3 --
! 114: int(5)
! 115:
! 116: -- Iteration 4 --
! 117: int(5)
! 118:
! 119: -- Iteration 5 --
! 120: int(4)
! 121:
! 122: -- Iteration 6 --
! 123: int(5)
! 124:
! 125: -- Iteration 7 --
! 126: int(12)
! 127:
! 128: -- Iteration 8 --
! 129: int(13)
! 130:
! 131: -- Iteration 9 --
! 132: int(3)
! 133:
! 134: -- Iteration 10 --
! 135: int(0)
! 136:
! 137: -- Iteration 11 --
! 138: int(0)
! 139:
! 140: -- Iteration 12 --
! 141: int(1)
! 142:
! 143: -- Iteration 13 --
! 144: int(0)
! 145:
! 146: -- Iteration 14 --
! 147: int(1)
! 148:
! 149: -- Iteration 15 --
! 150: int(0)
! 151:
! 152: -- Iteration 16 --
! 153: int(0)
! 154:
! 155: -- Iteration 17 --
! 156: int(0)
! 157:
! 158: -- Iteration 18 --
! 159: int(6)
! 160:
! 161: -- Iteration 19 --
! 162: int(6)
! 163:
! 164: -- Iteration 20 --
! 165: int(11)
! 166:
! 167: -- Iteration 21 --
! 168: int(14)
! 169:
! 170: -- Iteration 22 --
! 171: int(0)
! 172:
! 173: -- Iteration 23 --
! 174: int(0)
! 175:
! 176: -- Iteration 24 --
! 177:
! 178: Warning: mb_strlen() expects parameter 1 to be string, resource given in %s on line %d
! 179: bool(false)
! 180: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>