1--TEST--
2Test vfprintf() function : variation functionality
3--CREDITS--
4Felix De Vliegher <felix.devliegher@gmail.com>
5--INI--
6precision=14
7--FILE--
8<?php
9echo "*** Testing vfprintf() : variation functionality ***\n";
10
11// Open handle
12$file = 'vfprintf_variation1.txt';
13$fp = fopen( $file, 'a+' );
14
15$funset = fopen( __FILE__, 'r' );
16unset( $funset );
17
18class FooClass
19{
20    public function __toString()
21    {
22        return "Object";
23    }
24}
25
26// Output facilitating function
27function writeAndDump($fp, $format, $args)
28{
29    try {
30        ftruncate( $fp, 0 );
31        $length = vfprintf( $fp, $format, $args );
32        rewind( $fp );
33        $content = stream_get_contents( $fp );
34        var_dump( $content );
35        var_dump( $length );
36    } catch (TypeError $exception) {
37        echo $exception->getMessage() . "\n";
38    }
39}
40
41// Test vfprintf()
42writeAndDump( $fp, "format", null );
43writeAndDump( $fp, "Foo is %d and %s", array( 30, 'bar' ) );
44writeAndDump( $fp, "Foobar testing", array() );
45writeAndDump( $fp, "%s %s %s", array( 'bar', 'bar', 'bar' ) );
46writeAndDump( $fp, "%02d", array( 50 ) );
47writeAndDump( $fp, "", array() );
48writeAndDump( $fp, "Testing %b %d %f %o %s %x %X", array( 9, 6, 2.5502, 24, "foobar", 15, 65 ) );
49
50// Close handle
51fclose( $fp );
52
53?>
54--CLEAN--
55<?php
56
57$file = 'vfprintf_variation1.txt';
58unlink( $file );
59
60?>
61--EXPECT--
62*** Testing vfprintf() : variation functionality ***
63vfprintf(): Argument #3 ($values) must be of type array, null given
64string(17) "Foo is 30 and bar"
65int(17)
66string(14) "Foobar testing"
67int(14)
68string(11) "bar bar bar"
69int(11)
70string(2) "50"
71int(2)
72string(0) ""
73int(0)
74string(38) "Testing 1001 6 2.550200 30 foobar f 41"
75int(38)
76