1--TEST--
2Test vfprintf() function : variation functionality
3--CREDITS--
4Felix De Vliegher <felix.devliegher@gmail.com>
5--INI--
6precision=14
7--FILE--
8<?php
9/* Prototype  : int vfprintf(resource stream, string format, array args)
10 * Description: Output a formatted string into a stream
11 * Source code: ext/standard/formatted_print.c
12 * Alias to functions:
13 */
14
15echo "*** Testing vfprintf() : variation functionality ***\n";
16
17// Open handle
18$file = 'vfprintf_test.txt';
19$fp = fopen( $file, 'a+' );
20
21$funset = fopen( __FILE__, 'r' );
22unset( $funset );
23
24class FooClass
25{
26	public function __toString()
27	{
28		return "Object";
29	}
30}
31
32// Output facilitating function
33function writeAndDump($fp, $format, $args)
34{
35	ftruncate( $fp, 0 );
36	$length = vfprintf( $fp, $format, $args );
37	rewind( $fp );
38	$content = stream_get_contents( $fp );
39	var_dump( $content );
40	var_dump( $length );
41}
42
43// Test vfprintf()
44writeAndDump( $fp, "format", null );
45writeAndDump( $fp, "Foo is %d and %s", array( 30, 'bar' ) );
46writeAndDump( $fp, "Foobar testing", array() );
47writeAndDump( $fp, "%s %s %s", array( 'bar', 'bar', 'bar' ) );
48writeAndDump( $fp, "%02d", array( 50 ) );
49writeAndDump( $fp, "", array() );
50writeAndDump( $fp, "Testing %b %d %f %o %s %x %X", array( 9, 6, 2.5502, 24, "foobar", 15, 65 ) );
51@writeAndDump( $funset, "Foo with %s", array( 'string' ) );
52@writeAndDump( new FooClass(), "Foo with %s", array( 'string' ) );
53
54// Close handle
55fclose( $fp );
56
57?>
58===DONE===
59--CLEAN--
60<?php
61
62$file = 'vfprintf_test.txt';
63unlink( $file );
64
65?>
66--EXPECTF--
67*** Testing vfprintf() : variation functionality ***
68string(6) "format"
69int(6)
70string(17) "Foo is 30 and bar"
71int(17)
72string(14) "Foobar testing"
73int(14)
74string(11) "bar bar bar"
75int(11)
76string(2) "50"
77int(2)
78string(0) ""
79int(0)
80string(38) "Testing 1001 6 2.550200 30 foobar f 41"
81int(38)
82bool(false)
83bool(false)
84bool(false)
85bool(false)
86===DONE===
87