PageRenderTime 49ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/zend/good/ext/standard/tests/strings/vfprintf_variation3.php

http://github.com/facebook/hiphop-php
PHP | 63 lines | 38 code | 11 blank | 14 comment | 1 complexity | 5e228548fbbec60ceab88edd6acbdbd6 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?hh
  2. /* Prototype : int vfprintf ( resource $handle , string $format , array $args )
  3. * Description: Write a formatted string to a stream
  4. * Source code: ext/standard/formatted_print.c
  5. */
  6. /*
  7. * Test vfprintf() when different int formats and int values are passed to
  8. * the '$format' and '$args' arguments of the function
  9. */
  10. <<__EntryPoint>> function main(): void {
  11. echo "*** Testing vfprintf() : int formats with int values ***\n";
  12. // defining array of int formats
  13. $formats = varray[
  14. "%d",
  15. "%+d %-d %D",
  16. "%ld %Ld, %4d %-4d",
  17. "%10.4d %-10.4d %04d %04.4d",
  18. "%'#2d %'2d %'$2d %'_2d",
  19. "%d %d %d %d",
  20. "% %%d d%",
  21. '%3$d %4$d %1$d %2$d'
  22. ];
  23. // Arrays of int values for the format defined in $format.
  24. // Each sub array contains int values which correspond to each format string in $format
  25. $args_array = varray[
  26. varray[0],
  27. varray[-1, 1, +22],
  28. varray[2147483647, -2147483648, +2147483640, -2147483640],
  29. varray[123456, 12345678, -1234567, 1234567],
  30. varray[111, 2222, 333333, 44444444],
  31. varray[0x123b, 0xfAb, 0123, 01293],
  32. varray[1234, -5678, 2345],
  33. varray[3, 4, 1, 2]
  34. ];
  35. // looping to test vfprintf() with different int formats from the above $format array
  36. // and with int values from the above $args_array array
  37. /* creating dumping file */
  38. $data_file = dirname(__FILE__) . '/vfprintf_variation3.txt';
  39. if (!($fp = fopen($data_file, 'wt')))
  40. return;
  41. $counter = 1;
  42. foreach($formats as $format) {
  43. fprintf($fp, "\n-- Iteration %d --\n",$counter);
  44. vfprintf($fp, $format, $args_array[$counter-1]);
  45. $counter++;
  46. }
  47. fclose($fp);
  48. print_r(file_get_contents($data_file));
  49. echo "\n";
  50. unlink($data_file);
  51. echo "===DONE===\n";
  52. }