1--TEST-- 2Test sprintf() function : usage variations - unsigned formats with string values 3--SKIPIF-- 4<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); ?> 5--FILE-- 6<?php 7/* Prototype : string sprintf(string $format [, mixed $arg1 [, mixed ...]]) 8 * Description: Return a formatted string 9 * Source code: ext/standard/formatted_print.c 10*/ 11 12echo "*** Testing sprintf() : unsigned formats with string values ***\n"; 13 14// array of string values 15$string_values = array( 16 "", 17 '', 18 "0", 19 '0', 20 "1", 21 '1', 22 "-123", 23 "+123", 24 "\x01", 25 '\x01', 26 "\01", 27 '\01', 28 'string', 29 "string", 30 "true", 31 "FALSE", 32 'false', 33 'TRUE', 34 "NULL", 35 'null' 36); 37 38// array of unsigned formats 39$unsigned_formats = array( 40 "%u", "%hu", "%lu", 41 "%Lu", " %u", "%u ", 42 "\t%u", "\n%u", "%4u", 43 "%30u", "%[0-9]", "%*u" 44); 45 46 47$count = 1; 48foreach($string_values as $string_value) { 49 echo "\n-- Iteration $count --\n"; 50 51 foreach($unsigned_formats as $format) { 52 var_dump( sprintf($format, $string_value) ); 53 } 54 $count++; 55}; 56 57echo "Done"; 58?> 59--EXPECTF-- 60*** Testing sprintf() : unsigned formats with string values *** 61 62-- Iteration 1 -- 63string(1) "0" 64string(1) "u" 65string(1) "0" 66string(1) "u" 67string(2) " 0" 68string(2) "0 " 69string(2) " 0" 70string(2) " 710" 72string(4) " 0" 73string(30) " 0" 74string(4) "0-9]" 75string(1) "u" 76 77-- Iteration 2 -- 78string(1) "0" 79string(1) "u" 80string(1) "0" 81string(1) "u" 82string(2) " 0" 83string(2) "0 " 84string(2) " 0" 85string(2) " 860" 87string(4) " 0" 88string(30) " 0" 89string(4) "0-9]" 90string(1) "u" 91 92-- Iteration 3 -- 93string(1) "0" 94string(1) "u" 95string(1) "0" 96string(1) "u" 97string(2) " 0" 98string(2) "0 " 99string(2) " 0" 100string(2) " 1010" 102string(4) " 0" 103string(30) " 0" 104string(4) "0-9]" 105string(1) "u" 106 107-- Iteration 4 -- 108string(1) "0" 109string(1) "u" 110string(1) "0" 111string(1) "u" 112string(2) " 0" 113string(2) "0 " 114string(2) " 0" 115string(2) " 1160" 117string(4) " 0" 118string(30) " 0" 119string(4) "0-9]" 120string(1) "u" 121 122-- Iteration 5 -- 123string(1) "1" 124string(1) "u" 125string(1) "1" 126string(1) "u" 127string(2) " 1" 128string(2) "1 " 129string(2) " 1" 130string(2) " 1311" 132string(4) " 1" 133string(30) " 1" 134string(4) "0-9]" 135string(1) "u" 136 137-- Iteration 6 -- 138string(1) "1" 139string(1) "u" 140string(1) "1" 141string(1) "u" 142string(2) " 1" 143string(2) "1 " 144string(2) " 1" 145string(2) " 1461" 147string(4) " 1" 148string(30) " 1" 149string(4) "0-9]" 150string(1) "u" 151 152-- Iteration 7 -- 153string(20) "18446744073709551493" 154string(1) "u" 155string(20) "18446744073709551493" 156string(1) "u" 157string(21) " 18446744073709551493" 158string(21) "18446744073709551493 " 159string(21) " 18446744073709551493" 160string(21) " 16118446744073709551493" 162string(20) "18446744073709551493" 163string(30) " 18446744073709551493" 164string(4) "0-9]" 165string(1) "u" 166 167-- Iteration 8 -- 168string(3) "123" 169string(1) "u" 170string(3) "123" 171string(1) "u" 172string(4) " 123" 173string(4) "123 " 174string(4) " 123" 175string(4) " 176123" 177string(4) " 123" 178string(30) " 123" 179string(4) "0-9]" 180string(1) "u" 181 182-- Iteration 9 -- 183string(1) "0" 184string(1) "u" 185string(1) "0" 186string(1) "u" 187string(2) " 0" 188string(2) "0 " 189string(2) " 0" 190string(2) " 1910" 192string(4) " 0" 193string(30) " 0" 194string(4) "0-9]" 195string(1) "u" 196 197-- Iteration 10 -- 198string(1) "0" 199string(1) "u" 200string(1) "0" 201string(1) "u" 202string(2) " 0" 203string(2) "0 " 204string(2) " 0" 205string(2) " 2060" 207string(4) " 0" 208string(30) " 0" 209string(4) "0-9]" 210string(1) "u" 211 212-- Iteration 11 -- 213string(1) "0" 214string(1) "u" 215string(1) "0" 216string(1) "u" 217string(2) " 0" 218string(2) "0 " 219string(2) " 0" 220string(2) " 2210" 222string(4) " 0" 223string(30) " 0" 224string(4) "0-9]" 225string(1) "u" 226 227-- Iteration 12 -- 228string(1) "0" 229string(1) "u" 230string(1) "0" 231string(1) "u" 232string(2) " 0" 233string(2) "0 " 234string(2) " 0" 235string(2) " 2360" 237string(4) " 0" 238string(30) " 0" 239string(4) "0-9]" 240string(1) "u" 241 242-- Iteration 13 -- 243string(1) "0" 244string(1) "u" 245string(1) "0" 246string(1) "u" 247string(2) " 0" 248string(2) "0 " 249string(2) " 0" 250string(2) " 2510" 252string(4) " 0" 253string(30) " 0" 254string(4) "0-9]" 255string(1) "u" 256 257-- Iteration 14 -- 258string(1) "0" 259string(1) "u" 260string(1) "0" 261string(1) "u" 262string(2) " 0" 263string(2) "0 " 264string(2) " 0" 265string(2) " 2660" 267string(4) " 0" 268string(30) " 0" 269string(4) "0-9]" 270string(1) "u" 271 272-- Iteration 15 -- 273string(1) "0" 274string(1) "u" 275string(1) "0" 276string(1) "u" 277string(2) " 0" 278string(2) "0 " 279string(2) " 0" 280string(2) " 2810" 282string(4) " 0" 283string(30) " 0" 284string(4) "0-9]" 285string(1) "u" 286 287-- Iteration 16 -- 288string(1) "0" 289string(1) "u" 290string(1) "0" 291string(1) "u" 292string(2) " 0" 293string(2) "0 " 294string(2) " 0" 295string(2) " 2960" 297string(4) " 0" 298string(30) " 0" 299string(4) "0-9]" 300string(1) "u" 301 302-- Iteration 17 -- 303string(1) "0" 304string(1) "u" 305string(1) "0" 306string(1) "u" 307string(2) " 0" 308string(2) "0 " 309string(2) " 0" 310string(2) " 3110" 312string(4) " 0" 313string(30) " 0" 314string(4) "0-9]" 315string(1) "u" 316 317-- Iteration 18 -- 318string(1) "0" 319string(1) "u" 320string(1) "0" 321string(1) "u" 322string(2) " 0" 323string(2) "0 " 324string(2) " 0" 325string(2) " 3260" 327string(4) " 0" 328string(30) " 0" 329string(4) "0-9]" 330string(1) "u" 331 332-- Iteration 19 -- 333string(1) "0" 334string(1) "u" 335string(1) "0" 336string(1) "u" 337string(2) " 0" 338string(2) "0 " 339string(2) " 0" 340string(2) " 3410" 342string(4) " 0" 343string(30) " 0" 344string(4) "0-9]" 345string(1) "u" 346 347-- Iteration 20 -- 348string(1) "0" 349string(1) "u" 350string(1) "0" 351string(1) "u" 352string(2) " 0" 353string(2) "0 " 354string(2) " 0" 355string(2) " 3560" 357string(4) " 0" 358string(30) " 0" 359string(4) "0-9]" 360string(1) "u" 361Done 362