1--TEST-- 2Test sprintf() function : usage variations - hexa formats with integer values 3--SKIPIF-- 4<?php 5if (PHP_INT_SIZE != 4) { 6 die("skip this test is for 32bit platform only"); 7} 8?> 9--FILE-- 10<?php 11echo "*** Testing sprintf() : hexa formats with integer values ***\n"; 12 13// array of integer values 14$integer_values = array( 15 0, 16 1, 17 -1, 18 -2147483648, // max negative integer value 19 -2147483647, 20 2147483647, // max positive integer value 21 2147483640, 22 0x123B, // integer as hexadecimal 23 0x12ab, 24 0Xfff, 25 0XFA, 26 -0x80000000, // max negative integer as hexadecimal 27 0x7fffffff, // max positive integer as hexadecimal 28 0x7FFFFFFF, // max positive integer as hexadecimal 29 0123, // integer as octal 30 01, // should be quivalent to octal 1 31 -020000000000, // max negative integer as octal 32 017777777777 // max positive integer as octal 33); 34 35// array of hexa formats 36$hexa_formats = array( 37 "%x", "%xx", "%lx", " %x", "%x ", 38 "\t%x", "\n%x", "%4x", "%30x", 39); 40 41$count = 1; 42foreach($integer_values as $integer_value) { 43 echo "\n-- Iteration $count --\n"; 44 45 foreach($hexa_formats as $format) { 46 var_dump( sprintf($format, $integer_value) ); 47 } 48 $count++; 49}; 50 51echo "Done"; 52?> 53--EXPECT-- 54*** Testing sprintf() : hexa formats with integer values *** 55 56-- Iteration 1 -- 57string(1) "0" 58string(2) "0x" 59string(1) "0" 60string(2) " 0" 61string(2) "0 " 62string(2) " 0" 63string(2) " 640" 65string(4) " 0" 66string(30) " 0" 67 68-- Iteration 2 -- 69string(1) "1" 70string(2) "1x" 71string(1) "1" 72string(2) " 1" 73string(2) "1 " 74string(2) " 1" 75string(2) " 761" 77string(4) " 1" 78string(30) " 1" 79 80-- Iteration 3 -- 81string(8) "ffffffff" 82string(9) "ffffffffx" 83string(8) "ffffffff" 84string(9) " ffffffff" 85string(9) "ffffffff " 86string(9) " ffffffff" 87string(9) " 88ffffffff" 89string(8) "ffffffff" 90string(30) " ffffffff" 91 92-- Iteration 4 -- 93string(8) "80000000" 94string(9) "80000000x" 95string(8) "80000000" 96string(9) " 80000000" 97string(9) "80000000 " 98string(9) " 80000000" 99string(9) " 10080000000" 101string(8) "80000000" 102string(30) " 80000000" 103 104-- Iteration 5 -- 105string(8) "80000001" 106string(9) "80000001x" 107string(8) "80000001" 108string(9) " 80000001" 109string(9) "80000001 " 110string(9) " 80000001" 111string(9) " 11280000001" 113string(8) "80000001" 114string(30) " 80000001" 115 116-- Iteration 6 -- 117string(8) "7fffffff" 118string(9) "7fffffffx" 119string(8) "7fffffff" 120string(9) " 7fffffff" 121string(9) "7fffffff " 122string(9) " 7fffffff" 123string(9) " 1247fffffff" 125string(8) "7fffffff" 126string(30) " 7fffffff" 127 128-- Iteration 7 -- 129string(8) "7ffffff8" 130string(9) "7ffffff8x" 131string(8) "7ffffff8" 132string(9) " 7ffffff8" 133string(9) "7ffffff8 " 134string(9) " 7ffffff8" 135string(9) " 1367ffffff8" 137string(8) "7ffffff8" 138string(30) " 7ffffff8" 139 140-- Iteration 8 -- 141string(4) "123b" 142string(5) "123bx" 143string(4) "123b" 144string(5) " 123b" 145string(5) "123b " 146string(5) " 123b" 147string(5) " 148123b" 149string(4) "123b" 150string(30) " 123b" 151 152-- Iteration 9 -- 153string(4) "12ab" 154string(5) "12abx" 155string(4) "12ab" 156string(5) " 12ab" 157string(5) "12ab " 158string(5) " 12ab" 159string(5) " 16012ab" 161string(4) "12ab" 162string(30) " 12ab" 163 164-- Iteration 10 -- 165string(3) "fff" 166string(4) "fffx" 167string(3) "fff" 168string(4) " fff" 169string(4) "fff " 170string(4) " fff" 171string(4) " 172fff" 173string(4) " fff" 174string(30) " fff" 175 176-- Iteration 11 -- 177string(2) "fa" 178string(3) "fax" 179string(2) "fa" 180string(3) " fa" 181string(3) "fa " 182string(3) " fa" 183string(3) " 184fa" 185string(4) " fa" 186string(30) " fa" 187 188-- Iteration 12 -- 189string(8) "80000000" 190string(9) "80000000x" 191string(8) "80000000" 192string(9) " 80000000" 193string(9) "80000000 " 194string(9) " 80000000" 195string(9) " 19680000000" 197string(8) "80000000" 198string(30) " 80000000" 199 200-- Iteration 13 -- 201string(8) "7fffffff" 202string(9) "7fffffffx" 203string(8) "7fffffff" 204string(9) " 7fffffff" 205string(9) "7fffffff " 206string(9) " 7fffffff" 207string(9) " 2087fffffff" 209string(8) "7fffffff" 210string(30) " 7fffffff" 211 212-- Iteration 14 -- 213string(8) "7fffffff" 214string(9) "7fffffffx" 215string(8) "7fffffff" 216string(9) " 7fffffff" 217string(9) "7fffffff " 218string(9) " 7fffffff" 219string(9) " 2207fffffff" 221string(8) "7fffffff" 222string(30) " 7fffffff" 223 224-- Iteration 15 -- 225string(2) "53" 226string(3) "53x" 227string(2) "53" 228string(3) " 53" 229string(3) "53 " 230string(3) " 53" 231string(3) " 23253" 233string(4) " 53" 234string(30) " 53" 235 236-- Iteration 16 -- 237string(1) "1" 238string(2) "1x" 239string(1) "1" 240string(2) " 1" 241string(2) "1 " 242string(2) " 1" 243string(2) " 2441" 245string(4) " 1" 246string(30) " 1" 247 248-- Iteration 17 -- 249string(8) "80000000" 250string(9) "80000000x" 251string(8) "80000000" 252string(9) " 80000000" 253string(9) "80000000 " 254string(9) " 80000000" 255string(9) " 25680000000" 257string(8) "80000000" 258string(30) " 80000000" 259 260-- Iteration 18 -- 261string(8) "7fffffff" 262string(9) "7fffffffx" 263string(8) "7fffffff" 264string(9) " 7fffffff" 265string(9) "7fffffff " 266string(9) " 7fffffff" 267string(9) " 2687fffffff" 269string(8) "7fffffff" 270string(30) " 7fffffff" 271Done 272