Annotation of embedaddon/php/ext/standard/tests/general_functions/is_string.phpt, revision 1.1

1.1     ! misho       1: --TEST--
        !             2: Test is_string() function
        !             3: --FILE--
        !             4: <?php
        !             5: /* Prototype: bool is_string ( mixed $var );
        !             6:  * Description: Finds whether the given variable is a string
        !             7:  */
        !             8: 
        !             9: echo "*** Testing is_string() with valid string values ***\n";
        !            10: // different valid strings 
        !            11: 
        !            12: /* string created using Heredoc (<<<) */
        !            13: $heredoc_string = <<<EOT
        !            14: This is string defined
        !            15: using heredoc.
        !            16: EOT;
        !            17: /* heredoc string with only numerics */
        !            18: $heredoc_numeric_string = <<<EOT
        !            19: 123456 3993
        !            20: 4849 string 
        !            21: EOT;
        !            22: /* null heardoc string */
        !            23: $heredoc_empty_string = <<<EOT
        !            24: EOT;
        !            25: $heredoc_null_string = <<<EOT
        !            26: NULL
        !            27: EOT;
        !            28: 
        !            29: $strings = array(
        !            30:   "",
        !            31:   " ",
        !            32:   '',
        !            33:   ' ',
        !            34:   "string",
        !            35:   'string',
        !            36:   "NULL",
        !            37:   'null',
        !            38:   "FALSE",
        !            39:   'true',
        !            40:   "\x0b",
        !            41:   "\0",
        !            42:   '\0',
        !            43:   '\060',
        !            44:   "\070",
        !            45:   "0x55F",
        !            46:   "055",
        !            47:   "@#$#$%%$^^$%^%^$^&",
        !            48:   $heredoc_string,
        !            49:   $heredoc_numeric_string,
        !            50:   $heredoc_empty_string,
        !            51:   $heredoc_null_string
        !            52: );
        !            53: /* loop to check that is_string() recognizes different 
        !            54:    strings, expected output bool(true) */
        !            55: $loop_counter = 1;
        !            56: foreach ($strings as $string ) {
        !            57:   echo "-- Iteration $loop_counter --\n"; $loop_counter++;
        !            58:   var_dump( is_string($string) );
        !            59: }
        !            60: 
        !            61: echo "\n*** Testing is_string() on non string values ***\n";
        !            62: 
        !            63: // get a resource type variable
        !            64: $fp = fopen (__FILE__, "r");
        !            65: $dfp = opendir ( dirname(__FILE__) );
        !            66: 
        !            67: // unset vars
        !            68: $unset_string1 = "string";
        !            69: $unset_string2 = 'string';
        !            70: $unset_heredoc = <<<EOT
        !            71: this is heredoc string
        !            72: EOT;
        !            73: // unset the vars 
        !            74: unset($unset_string1, $unset_string2, $unset_heredoc);
        !            75: 
        !            76: // other types in a array 
        !            77: $not_strings = array (
        !            78:   /* integers */
        !            79:   0,
        !            80:   1,
        !            81:   -1,
        !            82:   -0,
        !            83:   543915,
        !            84:   -5322,
        !            85:   0x0,
        !            86:   0x1,
        !            87:   0x55F,
        !            88:   -0xCCF,
        !            89:   0123,
        !            90:   -0654,
        !            91:   00,
        !            92:   01,
        !            93: 
        !            94:   /* floats */
        !            95:   0.0,
        !            96:   1.0,
        !            97:   -1.0,
        !            98:   10.0000000000000000005,
        !            99:   .5e6,
        !           100:   -.5E7,
        !           101:   .5E+8,
        !           102:   -.5e+90,
        !           103:   1e5,
        !           104:   -1e5,
        !           105:   1E5,
        !           106:   -1E7,
        !           107: 
        !           108:   /* objects */
        !           109:   new stdclass,
        !           110: 
        !           111:   /* resources */
        !           112:   $fp,
        !           113:   $dfp,
        !           114: 
        !           115:   /* arrays */
        !           116:   array(),
        !           117:   array(0),
        !           118:   array(1),
        !           119:   array(NULL),
        !           120:   array(null),
        !           121:   array("string"),
        !           122:   array(true),
        !           123:   array(TRUE),
        !           124:   array(false),
        !           125:   array(FALSE),
        !           126:   array(1,2,3,4),
        !           127:   array(1 => "One", "two" => 2),
        !           128: 
        !           129:   /* undefined and unset vars */
        !           130:   @$unset_string1,
        !           131:   @$unset_string2,
        !           132:   @$unset_heredoc,
        !           133:   @$undefined_var 
        !           134: );
        !           135: /* loop through the $not_strings to see working of 
        !           136:    is_string() on non string types, expected output bool(false) */
        !           137: $loop_counter = 1;
        !           138: foreach ($not_strings as $type ) {
        !           139:   echo "-- Iteration $loop_counter --\n"; $loop_counter++;
        !           140:   var_dump( is_string($type) );
        !           141: }
        !           142: 
        !           143: echo "\n*** Testing error conditions ***\n";
        !           144: //Zero argument
        !           145: var_dump( is_string() );
        !           146: 
        !           147: //arguments more than expected 
        !           148: var_dump( is_string("string", "test") );
        !           149:  
        !           150: echo "Done\n";
        !           151: 
        !           152: // close the resources used
        !           153: fclose($fp);
        !           154: closedir($dfp);
        !           155: 
        !           156: ?>
        !           157: --EXPECTF--
        !           158: *** Testing is_string() with valid string values ***
        !           159: -- Iteration 1 --
        !           160: bool(true)
        !           161: -- Iteration 2 --
        !           162: bool(true)
        !           163: -- Iteration 3 --
        !           164: bool(true)
        !           165: -- Iteration 4 --
        !           166: bool(true)
        !           167: -- Iteration 5 --
        !           168: bool(true)
        !           169: -- Iteration 6 --
        !           170: bool(true)
        !           171: -- Iteration 7 --
        !           172: bool(true)
        !           173: -- Iteration 8 --
        !           174: bool(true)
        !           175: -- Iteration 9 --
        !           176: bool(true)
        !           177: -- Iteration 10 --
        !           178: bool(true)
        !           179: -- Iteration 11 --
        !           180: bool(true)
        !           181: -- Iteration 12 --
        !           182: bool(true)
        !           183: -- Iteration 13 --
        !           184: bool(true)
        !           185: -- Iteration 14 --
        !           186: bool(true)
        !           187: -- Iteration 15 --
        !           188: bool(true)
        !           189: -- Iteration 16 --
        !           190: bool(true)
        !           191: -- Iteration 17 --
        !           192: bool(true)
        !           193: -- Iteration 18 --
        !           194: bool(true)
        !           195: -- Iteration 19 --
        !           196: bool(true)
        !           197: -- Iteration 20 --
        !           198: bool(true)
        !           199: -- Iteration 21 --
        !           200: bool(true)
        !           201: -- Iteration 22 --
        !           202: bool(true)
        !           203: 
        !           204: *** Testing is_string() on non string values ***
        !           205: -- Iteration 1 --
        !           206: bool(false)
        !           207: -- Iteration 2 --
        !           208: bool(false)
        !           209: -- Iteration 3 --
        !           210: bool(false)
        !           211: -- Iteration 4 --
        !           212: bool(false)
        !           213: -- Iteration 5 --
        !           214: bool(false)
        !           215: -- Iteration 6 --
        !           216: bool(false)
        !           217: -- Iteration 7 --
        !           218: bool(false)
        !           219: -- Iteration 8 --
        !           220: bool(false)
        !           221: -- Iteration 9 --
        !           222: bool(false)
        !           223: -- Iteration 10 --
        !           224: bool(false)
        !           225: -- Iteration 11 --
        !           226: bool(false)
        !           227: -- Iteration 12 --
        !           228: bool(false)
        !           229: -- Iteration 13 --
        !           230: bool(false)
        !           231: -- Iteration 14 --
        !           232: bool(false)
        !           233: -- Iteration 15 --
        !           234: bool(false)
        !           235: -- Iteration 16 --
        !           236: bool(false)
        !           237: -- Iteration 17 --
        !           238: bool(false)
        !           239: -- Iteration 18 --
        !           240: bool(false)
        !           241: -- Iteration 19 --
        !           242: bool(false)
        !           243: -- Iteration 20 --
        !           244: bool(false)
        !           245: -- Iteration 21 --
        !           246: bool(false)
        !           247: -- Iteration 22 --
        !           248: bool(false)
        !           249: -- Iteration 23 --
        !           250: bool(false)
        !           251: -- Iteration 24 --
        !           252: bool(false)
        !           253: -- Iteration 25 --
        !           254: bool(false)
        !           255: -- Iteration 26 --
        !           256: bool(false)
        !           257: -- Iteration 27 --
        !           258: bool(false)
        !           259: -- Iteration 28 --
        !           260: bool(false)
        !           261: -- Iteration 29 --
        !           262: bool(false)
        !           263: -- Iteration 30 --
        !           264: bool(false)
        !           265: -- Iteration 31 --
        !           266: bool(false)
        !           267: -- Iteration 32 --
        !           268: bool(false)
        !           269: -- Iteration 33 --
        !           270: bool(false)
        !           271: -- Iteration 34 --
        !           272: bool(false)
        !           273: -- Iteration 35 --
        !           274: bool(false)
        !           275: -- Iteration 36 --
        !           276: bool(false)
        !           277: -- Iteration 37 --
        !           278: bool(false)
        !           279: -- Iteration 38 --
        !           280: bool(false)
        !           281: -- Iteration 39 --
        !           282: bool(false)
        !           283: -- Iteration 40 --
        !           284: bool(false)
        !           285: -- Iteration 41 --
        !           286: bool(false)
        !           287: -- Iteration 42 --
        !           288: bool(false)
        !           289: -- Iteration 43 --
        !           290: bool(false)
        !           291: -- Iteration 44 --
        !           292: bool(false)
        !           293: -- Iteration 45 --
        !           294: bool(false)
        !           295: 
        !           296: *** Testing error conditions ***
        !           297: 
        !           298: Warning: is_string() expects exactly 1 parameter, 0 given in %s on line %d
        !           299: bool(false)
        !           300: 
        !           301: Warning: is_string() expects exactly 1 parameter, 2 given in %s on line %d
        !           302: bool(false)
        !           303: Done

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