summaryrefslogtreecommitdiff
path: root/ext/standard/tests/strings/vfprintf_error3.phpt
blob: 703bc73ad8ced38af7f2c05a4bb9c8ba3f4b5221 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
--TEST--
Test vfprintf() function : error conditions (wrong argument types)
--CREDITS--
Felix De Vliegher <felix.devliegher@gmail.com>
--INI--
precision=14
--FILE--
<?php
// Open handle
$file = 'vfprintf_error3.txt';
$fp = fopen( $file, "a+" );

echo "\n-- Testing vfprintf() function with wrong variable types as argument --\n";
try {
  vfprintf($fp, array( 'foo %d', 'bar %s' ), 3.55552);
} catch (TypeError $exception) {
  echo $exception->getMessage() . "\n";
}

try {
    vfprintf($fp, "Foo: %s", "not available");
} catch (TypeError $e) {
    echo $e->getMessage(), "\n";
}

try {
    vfprintf($fp, "Foo %y fake", ["not available"]);
} catch (ValueError $e) {
    echo $e->getMessage(), "\n";
}

rewind( $fp );
var_dump( stream_get_contents( $fp ) );
ftruncate( $fp, 0 );
rewind( $fp );

// Close handle
fclose( $fp );

?>
--CLEAN--
<?php

$file = 'vfprintf_error3.txt';
unlink( $file );

?>
--EXPECT--
-- Testing vfprintf() function with wrong variable types as argument --
vfprintf(): Argument #2 ($format) must be of type string, array given
vfprintf(): Argument #3 ($args) must be of type array, string given
Unknown format specifier "y"
string(0) ""