Annotation of embedaddon/php/ext/mbstring/tests/mb_strrpos_variation3.phpt, revision 1.1

1.1     ! misho       1: --TEST--
        !             2: Test mb_strrpos() function : usage variations - Pass different data types as $offset arg
        !             3: --SKIPIF--
        !             4: <?php
        !             5: extension_loaded('mbstring') or die('skip');
        !             6: function_exists('mb_strrpos') or die("skip mb_strrpos() is not available in this build");
        !             7: ?>
        !             8: --FILE--
        !             9: <?php
        !            10: /* Prototype  : int mb_strrpos(string $haystack, string $needle [, int $offset [, string $encoding]])
        !            11:  * Description: Find position of last occurrence of a string within another 
        !            12:  * Source code: ext/mbstring/mbstring.c
        !            13:  */
        !            14: 
        !            15: /*
        !            16:  * Pass mb_strrpos() different data types as $offset argument to test behaviour
        !            17:  */
        !            18: 
        !            19: echo "*** Testing mb_strrpos() : usage variations ***\n";
        !            20: 
        !            21: // Initialise function arguments not being substituted
        !            22: $needle = b'a';
        !            23: $haystack = b'string_val';
        !            24: $encoding = 'utf-8';
        !            25: 
        !            26: //get an unset variable
        !            27: $unset_var = 10;
        !            28: unset ($unset_var);
        !            29: 
        !            30: // get a class
        !            31: class classA
        !            32: {
        !            33:   public function __toString() {
        !            34:     return b"7";
        !            35:   }
        !            36: }
        !            37: 
        !            38: // heredoc string
        !            39: $heredoc = b<<<EOT
        !            40: hello world
        !            41: EOT;
        !            42: 
        !            43: // unexpected values to be passed to $offset argument
        !            44: $inputs = array(
        !            45: 
        !            46:        // int data
        !            47: /*1*/  0,
        !            48:        1,
        !            49:        12345,
        !            50:        -2345,
        !            51: 
        !            52:        // float data
        !            53: /*5*/  10.5,
        !            54:        -10.5,
        !            55:        12.3456789000e10,
        !            56:        12.3456789000E-10,
        !            57:        .5,
        !            58: 
        !            59:        // null data
        !            60: /*10*/ NULL,
        !            61:        null,
        !            62: 
        !            63:        // boolean data
        !            64: /*12*/ true,
        !            65:        false,
        !            66:        TRUE,
        !            67:        FALSE,
        !            68:        
        !            69:        // object data
        !            70: /*16*/ new classA(),
        !            71: 
        !            72:        // undefined data
        !            73: /*17*/ @$undefined_var,
        !            74: 
        !            75:        // unset data
        !            76: /*18*/ @$unset_var
        !            77: );
        !            78: 
        !            79: // loop through each element of $inputs to check the behavior of mb_strrpos()
        !            80: $iterator = 1;
        !            81: foreach($inputs as $input) {
        !            82:   echo "\n-- Iteration $iterator --\n";
        !            83:   var_dump( mb_strrpos($haystack, $needle, $input, $encoding));
        !            84:   $iterator++;
        !            85: };
        !            86: 
        !            87: echo "Done";
        !            88: ?>
        !            89: --EXPECTF--
        !            90: *** Testing mb_strrpos() : usage variations ***
        !            91: 
        !            92: -- Iteration 1 --
        !            93: int(8)
        !            94: 
        !            95: -- Iteration 2 --
        !            96: int(8)
        !            97: 
        !            98: -- Iteration 3 --
        !            99: 
        !           100: Warning: mb_strrpos(): Offset is greater than the length of haystack string in %s on line %d
        !           101: bool(false)
        !           102: 
        !           103: -- Iteration 4 --
        !           104: 
        !           105: Warning: mb_strrpos(): Offset is greater than the length of haystack string in %s on line %d
        !           106: bool(false)
        !           107: 
        !           108: -- Iteration 5 --
        !           109: bool(false)
        !           110: 
        !           111: -- Iteration 6 --
        !           112: bool(false)
        !           113: 
        !           114: -- Iteration 7 --
        !           115: 
        !           116: Warning: mb_strrpos(): Offset is greater than the length of haystack string in %s on line %d
        !           117: bool(false)
        !           118: 
        !           119: -- Iteration 8 --
        !           120: int(8)
        !           121: 
        !           122: -- Iteration 9 --
        !           123: int(8)
        !           124: 
        !           125: -- Iteration 10 --
        !           126: int(8)
        !           127: 
        !           128: -- Iteration 11 --
        !           129: int(8)
        !           130: 
        !           131: -- Iteration 12 --
        !           132: int(8)
        !           133: 
        !           134: -- Iteration 13 --
        !           135: int(8)
        !           136: 
        !           137: -- Iteration 14 --
        !           138: int(8)
        !           139: 
        !           140: -- Iteration 15 --
        !           141: int(8)
        !           142: 
        !           143: -- Iteration 16 --
        !           144: 
        !           145: Notice: Object of class classA could not be converted to int in %s on line %d
        !           146: int(8)
        !           147: 
        !           148: -- Iteration 17 --
        !           149: int(8)
        !           150: 
        !           151: -- Iteration 18 --
        !           152: int(8)
        !           153: Done

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>