mirror of
https://github.com/php/php-src.git
synced 2026-04-21 06:51:18 +02:00
32a1ebbd43
These are no longer needed after https://wiki.php.net/rfc/always_enable_json Closes GH-5637
216 lines
2.1 KiB
PHP
216 lines
2.1 KiB
PHP
--TEST--
|
|
sprintf() formats with different types
|
|
--FILE--
|
|
<?php
|
|
|
|
$formats = ['s', 'd', 'u', 'f', 'c', 'x'];
|
|
$values = [null, false, true, 2, 3.5, "foo", [], [1], fopen(__FILE__, "r"), new stdClass];
|
|
|
|
foreach ($formats as $format) {
|
|
foreach ($values as $value) {
|
|
echo "$format with " . (is_resource($value) ? "resource" : json_encode($value)) . ":\n";
|
|
try {
|
|
echo sprintf("%" . $format, $value), "\n";
|
|
} catch (Error $e) {
|
|
echo $e->getMessage(), "\n";
|
|
}
|
|
echo "\n";
|
|
}
|
|
}
|
|
|
|
?>
|
|
--EXPECTF--
|
|
%s with null:
|
|
|
|
|
|
%s with false:
|
|
|
|
|
|
%s with true:
|
|
1
|
|
|
|
%s with 2:
|
|
2
|
|
|
|
s with 3.5:
|
|
3.5
|
|
|
|
%s with "foo":
|
|
foo
|
|
|
|
%s with []:
|
|
|
|
Warning: Array to string conversion in %s on line %d
|
|
Array
|
|
|
|
%s with [1]:
|
|
|
|
Warning: Array to string conversion in %s on line %d
|
|
Array
|
|
|
|
%s with resource:
|
|
Resource id #%d
|
|
|
|
%s with {}:
|
|
Object of class stdClass could not be converted to string
|
|
|
|
d with null:
|
|
0
|
|
|
|
d with false:
|
|
0
|
|
|
|
d with true:
|
|
1
|
|
|
|
d with 2:
|
|
2
|
|
|
|
d with 3.5:
|
|
3
|
|
|
|
d with "foo":
|
|
0
|
|
|
|
d with []:
|
|
0
|
|
|
|
d with [1]:
|
|
1
|
|
|
|
d with resource:
|
|
%d
|
|
|
|
d with {}:
|
|
|
|
Notice: Object of class stdClass could not be converted to int in %s on line %d
|
|
1
|
|
|
|
u with null:
|
|
0
|
|
|
|
u with false:
|
|
0
|
|
|
|
u with true:
|
|
1
|
|
|
|
u with 2:
|
|
2
|
|
|
|
u with 3.5:
|
|
3
|
|
|
|
u with "foo":
|
|
0
|
|
|
|
u with []:
|
|
0
|
|
|
|
u with [1]:
|
|
1
|
|
|
|
u with resource:
|
|
%d
|
|
|
|
u with {}:
|
|
|
|
Notice: Object of class stdClass could not be converted to int in %s on line %d
|
|
1
|
|
|
|
f with null:
|
|
0.000000
|
|
|
|
f with false:
|
|
0.000000
|
|
|
|
f with true:
|
|
1.000000
|
|
|
|
f with 2:
|
|
2.000000
|
|
|
|
f with 3.5:
|
|
3.500000
|
|
|
|
f with "foo":
|
|
0.000000
|
|
|
|
f with []:
|
|
0.000000
|
|
|
|
f with [1]:
|
|
1.000000
|
|
|
|
f with resource:
|
|
%d.000000
|
|
|
|
f with {}:
|
|
|
|
Notice: Object of class stdClass could not be converted to float in %s on line %d
|
|
1.000000
|
|
|
|
c with null:
|
|
|