Annotation of embedaddon/php/ext/standard/tests/strings/lcfirst.phpt, revision 1.1

1.1     ! misho       1: --TEST--
        !             2: "lcfirst()" function
        !             3: --INI--
        !             4: precision=14
        !             5: --FILE--
        !             6: <?php
        !             7: /* Make a string's first character uppercase */
        !             8: 
        !             9: echo "#### Basic and Various operations ####\n";
        !            10: $str_array = array(
        !            11:                    "TesTing lcfirst.",
        !            12:                    "1.testing lcfirst",
        !            13:                    "HELLO wORLD",
        !            14:                    'HELLO wORLD',
        !            15:                     "\0",              // Null 
        !            16:                     "\x00",            // Hex Null
        !            17:                     "\x000",
        !            18:                     "abcd",            // double quoted string
        !            19:                     'xyz',             // single quoted string
        !            20:                     string,            // without quotes
        !            21:                     "-3",
        !            22:                     -3,
        !            23:                     '-3.344',
        !            24:                     -3.344,
        !            25:                     NULL,
        !            26:                     "NULL",
        !            27:                     "0",
        !            28:                     0,
        !            29:                     TRUE,              // bool type
        !            30:                     "TRUE",
        !            31:                     "1",
        !            32:                     1,
        !            33:                     1.234444,
        !            34:                     FALSE,
        !            35:                     "FALSE",
        !            36:                     " ",
        !            37:                     "     ",
        !            38:                     'b',               // single char
        !            39:                     '\t',              // escape sequences
        !            40:                     "\t",
        !            41:                     "12",
        !            42:                     "12twelve",                // int + string
        !            43:                  );
        !            44: /* loop to test working of lcfirst with different values */
        !            45: foreach ($str_array as $string) {
        !            46:   var_dump( lcfirst($string) );
        !            47: }
        !            48: 
        !            49: 
        !            50: 
        !            51: echo "\n#### Testing Miscelleneous inputs ####\n";
        !            52: 
        !            53: echo "--- Testing arrays ---";
        !            54: $str_arr = array("Hello", "?world", "!$%**()%**[][[[&@#~!", array());
        !            55: var_dump( lcfirst($str_arr) );  
        !            56: 
        !            57: echo "\n--- Testing lowercamelcase action call example ---\n";
        !            58: class Setter {
        !            59:     
        !            60:     protected $vars = array('partnerName' => false);
        !            61:     
        !            62:     public function __call($m, $v) {
        !            63:         if (stristr($m, 'set')) {
        !            64:             $action = lcfirst(substr($m, 3));
        !            65:             $this->$action = $v[0];
        !            66:         }
        !            67:     }
        !            68: 
        !            69:     public function __set($key, $value) {
        !            70:         if (array_key_exists($key, $this->vars)) {
        !            71:             $this->vars[$key] = $value;
        !            72:         }
        !            73:     }
        !            74: 
        !            75:     public function __get($key) {
        !            76:         if (array_key_exists($key, $this->vars)) {
        !            77:             return $this->vars[$key];
        !            78:         }
        !            79:     }
        !            80: }
        !            81: 
        !            82: $class = new Setter();
        !            83: $class->setPartnerName('partnerName');
        !            84: var_dump($class->partnerName);
        !            85: 
        !            86: echo "\n--- Testing objects ---\n";
        !            87: /* we get "Catchable fatal error: saying Object of class could not be converted
        !            88:         to string" by default when an object is passed instead of string:
        !            89: The error can be  avoided by chosing the __toString magix method as follows: */
        !            90: 
        !            91: class string {
        !            92:   function __toString() {
        !            93:     return "Hello world";
        !            94:   }
        !            95: }
        !            96: $obj_string = new string;
        !            97: 
        !            98: var_dump(lcfirst("$obj_string"));
        !            99: 
        !           100: 
        !           101: echo "\n--- Testing Resources ---\n";
        !           102: $filename1 = "dummy.txt";
        !           103: $file1 = fopen($filename1, "w");                // creating new file
        !           104: 
        !           105: /* getting resource type for file handle */
        !           106: $string1 = get_resource_type($file1);
        !           107: $string2 = (int)get_resource_type($file1);      // converting stream type to int
        !           108: 
        !           109: /* $string1 is of "stream" type */
        !           110: var_dump(lcfirst($string1)); 
        !           111: 
        !           112: /* $string2 holds a value of "int(0)" */
        !           113: var_dump(lcfirst($string2));
        !           114: 
        !           115: fclose($file1);                                 // closing the file "dummy.txt"
        !           116: unlink("$filename1");                           // deletes "dummy.txt"
        !           117: 
        !           118: 
        !           119: echo "\n--- Testing a longer and heredoc string ---\n";
        !           120: $string = <<<EOD
        !           121: Abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
        !           122: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
        !           123: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
        !           124: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
        !           125: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
        !           126: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
        !           127: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
        !           128: @#$%^&**&^%$#@!~:())))((((&&&**%$###@@@!!!~~~~@###$%^&*
        !           129: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
        !           130: EOD;
        !           131: var_dump(lcfirst($string));
        !           132: 
        !           133: echo "\n--- Testing a heredoc null string ---\n";
        !           134: $str = <<<EOD
        !           135: EOD;
        !           136: var_dump(lcfirst($str));
        !           137: 
        !           138: 
        !           139: echo "\n--- Testing simple and complex syntax strings ---\n";
        !           140: $str = 'world';
        !           141: 
        !           142: /* Simple syntax */
        !           143: var_dump(lcfirst("$str"));
        !           144: var_dump(lcfirst("$str'S"));
        !           145: var_dump(lcfirst("$strS"));
        !           146: 
        !           147: /* String with curly braces, complex syntax */
        !           148: var_dump(lcfirst("${str}S"));
        !           149: var_dump(lcfirst("{$str}S"));
        !           150: 
        !           151: echo "\n--- Nested lcfirst() ---\n";
        !           152: var_dump(lcfirst(lcfirst("hello")));
        !           153: 
        !           154: 
        !           155: echo "\n#### error conditions ####";
        !           156: /* Zero arguments */
        !           157: lcfirst();
        !           158: /* More than expected no. of args */
        !           159: lcfirst($str_array[0], $str_array[1]);
        !           160: lcfirst((int)10, (int)20);
        !           161: 
        !           162: echo "Done\n";
        !           163: ?>
        !           164: --EXPECTF--
        !           165: #### Basic and Various operations ####
        !           166: 
        !           167: Notice: Use of undefined constant string - assumed 'string' in %s on line %d
        !           168: string(16) "tesTing lcfirst."
        !           169: string(17) "1.testing lcfirst"
        !           170: string(11) "hELLO wORLD"
        !           171: string(11) "hELLO wORLD"
        !           172: string(1) ""
        !           173: string(1) ""
        !           174: string(2) "0"
        !           175: string(4) "abcd"
        !           176: string(3) "xyz"
        !           177: string(6) "string"
        !           178: string(2) "-3"
        !           179: string(2) "-3"
        !           180: string(6) "-3.344"
        !           181: string(6) "-3.344"
        !           182: string(0) ""
        !           183: string(4) "nULL"
        !           184: string(1) "0"
        !           185: string(1) "0"
        !           186: string(1) "1"
        !           187: string(4) "tRUE"
        !           188: string(1) "1"
        !           189: string(1) "1"
        !           190: string(8) "1.234444"
        !           191: string(0) ""
        !           192: string(5) "fALSE"
        !           193: string(1) " "
        !           194: string(5) "     "
        !           195: string(1) "b"
        !           196: string(2) "\t"
        !           197: string(1) "    "
        !           198: string(2) "12"
        !           199: string(8) "12twelve"
        !           200: 
        !           201: #### Testing Miscelleneous inputs ####
        !           202: --- Testing arrays ---
        !           203: Warning: lcfirst() expects parameter 1 to be string, array given in %s on line %d
        !           204: NULL
        !           205: 
        !           206: --- Testing lowercamelcase action call example ---
        !           207: string(%d) "partnerName"
        !           208: 
        !           209: --- Testing objects ---
        !           210: string(11) "hello world"
        !           211: 
        !           212: --- Testing Resources ---
        !           213: string(6) "stream"
        !           214: string(1) "0"
        !           215: 
        !           216: --- Testing a longer and heredoc string ---
        !           217: string(639) "abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
        !           218: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
        !           219: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
        !           220: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
        !           221: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
        !           222: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
        !           223: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
        !           224: @#$%^&**&^%$#@!~:())))((((&&&**%$###@@@!!!~~~~@###$%^&*
        !           225: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789"
        !           226: 
        !           227: --- Testing a heredoc null string ---
        !           228: string(0) ""
        !           229: 
        !           230: --- Testing simple and complex syntax strings ---
        !           231: string(5) "world"
        !           232: string(7) "world'S"
        !           233: 
        !           234: Notice: Undefined variable: strS in %s on line %d
        !           235: string(0) ""
        !           236: string(6) "worldS"
        !           237: string(6) "worldS"
        !           238: 
        !           239: --- Nested lcfirst() ---
        !           240: string(5) "hello"
        !           241: 
        !           242: #### error conditions ####
        !           243: Warning: lcfirst() expects exactly 1 parameter, 0 given in %s on line %d
        !           244: 
        !           245: Warning: lcfirst() expects exactly 1 parameter, 2 given in %s on line %d
        !           246: 
        !           247: Warning: lcfirst() expects exactly 1 parameter, 2 given in %s on line %d
        !           248: Done

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