1--TEST--
2Test sprintf() function : usage variations - int formats with resource values
3--FILE--
4<?php
5/* Prototype  : string sprintf(string $format [, mixed $arg1 [, mixed ...]])
6 * Description: Return a formatted string
7 * Source code: ext/standard/formatted_print.c
8*/
9
10echo "*** Testing sprintf() : integer formats with resource values ***\n";
11
12// resource type variable
13$fp = fopen (__FILE__, "r");
14$dfp = opendir ( dirname(__FILE__) );
15
16$fp_copy = $fp;
17$dfp_copy = $dfp;
18
19// array of resource types
20$resource_types = array (
21  $fp_copy,
22  $dfp_copy
23);
24
25// various integer formats
26$int_formats = array(
27  "%d", "%Ld", " %d",
28  "\t%d", "\n%d", "%4d",
29  "%[0-9]", "%*d"
30);
31
32$count = 1;
33foreach($resource_types as $res) {
34  echo "\n-- Iteration $count --\n";
35
36  foreach($int_formats as $format) {
37    var_dump( sprintf($format, $res) );
38  }
39  $count++;
40};
41
42// closing the resources
43fclose($fp);
44closedir($dfp);
45
46
47echo "Done";
48?>
49--EXPECTF--
50*** Testing sprintf() : integer formats with resource values ***
51
52-- Iteration 1 --
53string(%d) "%d"
54string(1) "d"
55string(%d) " %d"
56string(%d) "	%d"
57string(%d) "
58%d"
59string(%d) "%s%d"
60string(%d) "0-9]"
61string(1) "d"
62
63-- Iteration 2 --
64string(%d) "%d"
65string(1) "d"
66string(%d) " %d"
67string(%d) "	%d"
68string(%d) "
69%d"
70string(%d) "%s%d"
71string(%d) "0-9]"
72string(1) "d"
73Done
74