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) "