1--TEST-- 2Test sprintf() function : usage variations - octal 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() : octal 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 octal formats 37$octal_formats = array( 38 "%o", "%ho", "%lo", 39 "%Lo", " %o", "%o ", 40 "\t%o", "\n%o", "%4o", 41 "%30o", "%[0-7]", "%*o" 42); 43 44$count = 1; 45foreach($integer_values as $integer_value) { 46 echo "\n-- Iteration $count --\n"; 47 48 foreach($octal_formats as $format) { 49 var_dump( sprintf($format, $integer_value) ); 50 } 51 $count++; 52}; 53 54echo "Done"; 55?> 56--EXPECT-- 57*** Testing sprintf() : octal formats with integer values *** 58 59-- Iteration 1 -- 60string(1) "0" 61string(1) "o" 62string(1) "0" 63string(1) "o" 64string(2) " 0" 65string(2) "0 " 66string(2) " 0" 67string(2) " 680" 69string(4) " 0" 70string(30) " 0" 71string(4) "0-7]" 72string(1) "o" 73 74-- Iteration 2 -- 75string(1) "1" 76string(1) "o" 77string(1) "1" 78string(1) "o" 79string(2) " 1" 80string(2) "1 " 81string(2) " 1" 82string(2) " 831" 84string(4) " 1" 85string(30) " 1" 86string(4) "0-7]" 87string(1) "o" 88 89-- Iteration 3 -- 90string(22) "1777777777777777777777" 91string(1) "o" 92string(22) "1777777777777777777777" 93string(1) "o" 94string(23) " 1777777777777777777777" 95string(23) "1777777777777777777777 " 96string(23) " 1777777777777777777777" 97string(23) " 981777777777777777777777" 99string(22) "1777777777777777777777" 100string(30) " 1777777777777777777777" 101string(4) "0-7]" 102string(1) "o" 103 104-- Iteration 4 -- 105string(22) "1777777777760000000000" 106string(1) "o" 107string(22) "1777777777760000000000" 108string(1) "o" 109string(23) " 1777777777760000000000" 110string(23) "1777777777760000000000 " 111string(23) " 1777777777760000000000" 112string(23) " 1131777777777760000000000" 114string(22) "1777777777760000000000" 115string(30) " 1777777777760000000000" 116string(4) "0-7]" 117string(1) "o" 118 119-- Iteration 5 -- 120string(22) "1777777777760000000001" 121string(1) "o" 122string(22) "1777777777760000000001" 123string(1) "o" 124string(23) " 1777777777760000000001" 125string(23) "1777777777760000000001 " 126string(23) " 1777777777760000000001" 127string(23) " 1281777777777760000000001" 129string(22) "1777777777760000000001" 130string(30) " 1777777777760000000001" 131string(4) "0-7]" 132string(1) "o" 133 134-- Iteration 6 -- 135string(11) "17777777777" 136string(1) "o" 137string(11) "17777777777" 138string(1) "o" 139string(12) " 17777777777" 140string(12) "17777777777 " 141string(12) " 17777777777" 142string(12) " 14317777777777" 144string(11) "17777777777" 145string(30) " 17777777777" 146string(4) "0-7]" 147string(1) "o" 148 149-- Iteration 7 -- 150string(11) "17777777770" 151string(1) "o" 152string(11) "17777777770" 153string(1) "o" 154string(12) " 17777777770" 155string(12) "17777777770 " 156string(12) " 17777777770" 157string(12) " 15817777777770" 159string(11) "17777777770" 160string(30) " 17777777770" 161string(4) "0-7]" 162string(1) "o" 163 164-- Iteration 8 -- 165string(5) "11073" 166string(1) "o" 167string(5) "11073" 168string(1) "o" 169string(6) " 11073" 170string(6) "11073 " 171string(6) " 11073" 172string(6) " 17311073" 174string(5) "11073" 175string(30) " 11073" 176string(4) "0-7]" 177string(1) "o" 178 179-- Iteration 9 -- 180string(5) "11253" 181string(1) "o" 182string(5) "11253" 183string(1) "o" 184string(6) " 11253" 185string(6) "11253 " 186string(6) " 11253" 187string(6) " 18811253" 189string(5) "11253" 190string(30) " 11253" 191string(4) "0-7]" 192string(1) "o" 193 194-- Iteration 10 -- 195string(4) "7777" 196string(1) "o" 197string(4) "7777" 198string(1) "o" 199string(5) " 7777" 200string(5) "7777 " 201string(5) " 7777" 202string(5) " 2037777" 204string(4) "7777" 205string(30) " 7777" 206string(4) "0-7]" 207string(1) "o" 208 209-- Iteration 11 -- 210string(3) "372" 211string(1) "o" 212string(3) "372" 213string(1) "o" 214string(4) " 372" 215string(4) "372 " 216string(4) " 372" 217string(4) " 218372" 219string(4) " 372" 220string(30) " 372" 221string(4) "0-7]" 222string(1) "o" 223 224-- Iteration 12 -- 225string(22) "1777777777760000000000" 226string(1) "o" 227string(22) "1777777777760000000000" 228string(1) "o" 229string(23) " 1777777777760000000000" 230string(23) "1777777777760000000000 " 231string(23) " 1777777777760000000000" 232string(23) " 2331777777777760000000000" 234string(22) "1777777777760000000000" 235string(30) " 1777777777760000000000" 236string(4) "0-7]" 237string(1) "o" 238 239-- Iteration 13 -- 240string(11) "17777777777" 241string(1) "o" 242string(11) "17777777777" 243string(1) "o" 244string(12) " 17777777777" 245string(12) "17777777777 " 246string(12) " 17777777777" 247string(12) " 24817777777777" 249string(11) "17777777777" 250string(30) " 17777777777" 251string(4) "0-7]" 252string(1) "o" 253 254-- Iteration 14 -- 255string(11) "17777777777" 256string(1) "o" 257string(11) "17777777777" 258string(1) "o" 259string(12) " 17777777777" 260string(12) "17777777777 " 261string(12) " 17777777777" 262string(12) " 26317777777777" 264string(11) "17777777777" 265string(30) " 17777777777" 266string(4) "0-7]" 267string(1) "o" 268 269-- Iteration 15 -- 270string(3) "123" 271string(1) "o" 272string(3) "123" 273string(1) "o" 274string(4) " 123" 275string(4) "123 " 276string(4) " 123" 277string(4) " 278123" 279string(4) " 123" 280string(30) " 123" 281string(4) "0-7]" 282string(1) "o" 283 284-- Iteration 16 -- 285string(1) "1" 286string(1) "o" 287string(1) "1" 288string(1) "o" 289string(2) " 1" 290string(2) "1 " 291string(2) " 1" 292string(2) " 2931" 294string(4) " 1" 295string(30) " 1" 296string(4) "0-7]" 297string(1) "o" 298 299-- Iteration 17 -- 300string(22) "1777777777760000000000" 301string(1) "o" 302string(22) "1777777777760000000000" 303string(1) "o" 304string(23) " 1777777777760000000000" 305string(23) "1777777777760000000000 " 306string(23) " 1777777777760000000000" 307string(23) " 3081777777777760000000000" 309string(22) "1777777777760000000000" 310string(30) " 1777777777760000000000" 311string(4) "0-7]" 312string(1) "o" 313 314-- Iteration 18 -- 315string(11) "17777777777" 316string(1) "o" 317string(11) "17777777777" 318string(1) "o" 319string(12) " 17777777777" 320string(12) "17777777777 " 321string(12) " 17777777777" 322string(12) " 32317777777777" 324string(11) "17777777777" 325string(30) " 17777777777" 326string(4) "0-7]" 327string(1) "o" 328Done 329