1--TEST-- 2Test sprintf() function : usage variations - unsigned formats with integer 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 integer values ***\n"; 13 14// array of integer values 15$integer_values = array( 16 0, 17 1, 18 -1, 19 -2147483648, // max negative integer value 20 -2147483647, 21 2147483647, // max positive integer value 22 +2147483640, 23 0x123B, // integer as hexadecimal 24 0x12ab, 25 0Xfff, 26 0XFA, 27 -0x80000000, // max negative integer as hexadecimal 28 0x7fffffff, // max positive integer as hexadecimal 29 0x7FFFFFFF, // max positive integer as hexadecimal 30 0123, // integer as octal 31 01, // should be quivalent to octal 1 32 -020000000000, // max negative integer as octal 33 017777777777 // max positive integer as octal 34); 35 36// array of unsigned formats 37$unsigned_formats = array( 38 "%u", "%hu", "%lu", 39 "%Lu", " %u", "%u ", 40 "\t%u", "\n%u", "%4u", 41 "%30u", "%[0-9]", "%*u" 42); 43 44 45$count = 1; 46foreach($integer_values as $integer_value) { 47 echo "\n-- Iteration $count --\n"; 48 49 foreach($unsigned_formats as $format) { 50 var_dump( sprintf($format, $integer_value) ); 51 } 52 $count++; 53}; 54 55echo "Done"; 56?> 57--EXPECTF-- 58*** Testing sprintf() : unsigned formats with integer values *** 59 60-- Iteration 1 -- 61string(1) "0" 62string(1) "u" 63string(1) "0" 64string(1) "u" 65string(2) " 0" 66string(2) "0 " 67string(2) " 0" 68string(2) " 690" 70string(4) " 0" 71string(30) " 0" 72string(4) "0-9]" 73string(1) "u" 74 75-- Iteration 2 -- 76string(1) "1" 77string(1) "u" 78string(1) "1" 79string(1) "u" 80string(2) " 1" 81string(2) "1 " 82string(2) " 1" 83string(2) " 841" 85string(4) " 1" 86string(30) " 1" 87string(4) "0-9]" 88string(1) "u" 89 90-- Iteration 3 -- 91string(20) "18446744073709551615" 92string(1) "u" 93string(20) "18446744073709551615" 94string(1) "u" 95string(21) " 18446744073709551615" 96string(21) "18446744073709551615 " 97string(21) " 18446744073709551615" 98string(21) " 9918446744073709551615" 100string(20) "18446744073709551615" 101string(30) " 18446744073709551615" 102string(4) "0-9]" 103string(1) "u" 104 105-- Iteration 4 -- 106string(20) "18446744071562067968" 107string(1) "u" 108string(20) "18446744071562067968" 109string(1) "u" 110string(21) " 18446744071562067968" 111string(21) "18446744071562067968 " 112string(21) " 18446744071562067968" 113string(21) " 11418446744071562067968" 115string(20) "18446744071562067968" 116string(30) " 18446744071562067968" 117string(4) "0-9]" 118string(1) "u" 119 120-- Iteration 5 -- 121string(20) "18446744071562067969" 122string(1) "u" 123string(20) "18446744071562067969" 124string(1) "u" 125string(21) " 18446744071562067969" 126string(21) "18446744071562067969 " 127string(21) " 18446744071562067969" 128string(21) " 12918446744071562067969" 130string(20) "18446744071562067969" 131string(30) " 18446744071562067969" 132string(4) "0-9]" 133string(1) "u" 134 135-- Iteration 6 -- 136string(10) "2147483647" 137string(1) "u" 138string(10) "2147483647" 139string(1) "u" 140string(11) " 2147483647" 141string(11) "2147483647 " 142string(11) " 2147483647" 143string(11) " 1442147483647" 145string(10) "2147483647" 146string(30) " 2147483647" 147string(4) "0-9]" 148string(1) "u" 149 150-- Iteration 7 -- 151string(10) "2147483640" 152string(1) "u" 153string(10) "2147483640" 154string(1) "u" 155string(11) " 2147483640" 156string(11) "2147483640 " 157string(11) " 2147483640" 158string(11) " 1592147483640" 160string(10) "2147483640" 161string(30) " 2147483640" 162string(4) "0-9]" 163string(1) "u" 164 165-- Iteration 8 -- 166string(4) "4667" 167string(1) "u" 168string(4) "4667" 169string(1) "u" 170string(5) " 4667" 171string(5) "4667 " 172string(5) " 4667" 173string(5) " 1744667" 175string(4) "4667" 176string(30) " 4667" 177string(4) "0-9]" 178string(1) "u" 179 180-- Iteration 9 -- 181string(4) "4779" 182string(1) "u" 183string(4) "4779" 184string(1) "u" 185string(5) " 4779" 186string(5) "4779 " 187string(5) " 4779" 188string(5) " 1894779" 190string(4) "4779" 191string(30) " 4779" 192string(4) "0-9]" 193string(1) "u" 194 195-- Iteration 10 -- 196string(4) "4095" 197string(1) "u" 198string(4) "4095" 199string(1) "u" 200string(5) " 4095" 201string(5) "4095 " 202string(5) " 4095" 203string(5) " 2044095" 205string(4) "4095" 206string(30) " 4095" 207string(4) "0-9]" 208string(1) "u" 209 210-- Iteration 11 -- 211string(3) "250" 212string(1) "u" 213string(3) "250" 214string(1) "u" 215string(4) " 250" 216string(4) "250 " 217string(4) " 250" 218string(4) " 219250" 220string(4) " 250" 221string(30) " 250" 222string(4) "0-9]" 223string(1) "u" 224 225-- Iteration 12 -- 226string(20) "18446744071562067968" 227string(1) "u" 228string(20) "18446744071562067968" 229string(1) "u" 230string(21) " 18446744071562067968" 231string(21) "18446744071562067968 " 232string(21) " 18446744071562067968" 233string(21) " 23418446744071562067968" 235string(20) "18446744071562067968" 236string(30) " 18446744071562067968" 237string(4) "0-9]" 238string(1) "u" 239 240-- Iteration 13 -- 241string(10) "2147483647" 242string(1) "u" 243string(10) "2147483647" 244string(1) "u" 245string(11) " 2147483647" 246string(11) "2147483647 " 247string(11) " 2147483647" 248string(11) " 2492147483647" 250string(10) "2147483647" 251string(30) " 2147483647" 252string(4) "0-9]" 253string(1) "u" 254 255-- Iteration 14 -- 256string(10) "2147483647" 257string(1) "u" 258string(10) "2147483647" 259string(1) "u" 260string(11) " 2147483647" 261string(11) "2147483647 " 262string(11) " 2147483647" 263string(11) " 2642147483647" 265string(10) "2147483647" 266string(30) " 2147483647" 267string(4) "0-9]" 268string(1) "u" 269 270-- Iteration 15 -- 271string(2) "83" 272string(1) "u" 273string(2) "83" 274string(1) "u" 275string(3) " 83" 276string(3) "83 " 277string(3) " 83" 278string(3) " 27983" 280string(4) " 83" 281string(30) " 83" 282string(4) "0-9]" 283string(1) "u" 284 285-- Iteration 16 -- 286string(1) "1" 287string(1) "u" 288string(1) "1" 289string(1) "u" 290string(2) " 1" 291string(2) "1 " 292string(2) " 1" 293string(2) " 2941" 295string(4) " 1" 296string(30) " 1" 297string(4) "0-9]" 298string(1) "u" 299 300-- Iteration 17 -- 301string(20) "18446744071562067968" 302string(1) "u" 303string(20) "18446744071562067968" 304string(1) "u" 305string(21) " 18446744071562067968" 306string(21) "18446744071562067968 " 307string(21) " 18446744071562067968" 308string(21) " 30918446744071562067968" 310string(20) "18446744071562067968" 311string(30) " 18446744071562067968" 312string(4) "0-9]" 313string(1) "u" 314 315-- Iteration 18 -- 316string(10) "2147483647" 317string(1) "u" 318string(10) "2147483647" 319string(1) "u" 320string(11) " 2147483647" 321string(11) "2147483647 " 322string(11) " 2147483647" 323string(11) " 3242147483647" 325string(10) "2147483647" 326string(30) " 2147483647" 327string(4) "0-9]" 328string(1) "u" 329Done 330