xref: /php-src/Zend/tests/number_or_str_zpp.phpt (revision 80e90ad7)
1--TEST--
2Test Z_PARAM_NUMBER_OR_STR() and Z_PARAM_NUMBER_OR_STR_OR_NULL
3--EXTENSIONS--
4zend_test
5--FILE--
6<?php
7
8class Foo {}
9class ToString {
10    public function __toString() {
11        return "ToString";
12    }
13}
14
15var_dump(zend_number_or_string("string"));
16var_dump(zend_number_or_string(1));
17var_dump(zend_number_or_string(5.5));
18var_dump(zend_number_or_string(null));
19var_dump(zend_number_or_string(false));
20var_dump(zend_number_or_string(true));
21var_dump(zend_number_or_string(new ToString()));
22
23try {
24    zend_string_or_object([]);
25} catch (TypeError $exception) {
26    echo $exception->getMessage() . "\n";
27}
28try {
29    zend_number_or_string(new Foo());
30} catch (TypeError $exception) {
31    echo $exception->getMessage() . "\n";
32}
33
34var_dump(zend_number_or_string_or_null("string"));
35var_dump(zend_number_or_string_or_null(1));
36var_dump(zend_number_or_string_or_null(5.5));
37var_dump(zend_number_or_string_or_null(null));
38var_dump(zend_number_or_string_or_null(false));
39var_dump(zend_number_or_string_or_null(true));
40var_dump(zend_number_or_string_or_null(new ToString()));
41
42try {
43    zend_number_or_string_or_null([]);
44} catch (TypeError $exception) {
45    echo $exception->getMessage() . "\n";
46}
47try {
48    zend_number_or_string_or_null(new Foo());
49} catch (TypeError $exception) {
50    echo $exception->getMessage() . "\n";
51}
52
53?>
54--EXPECTF--
55string(6) "string"
56int(1)
57float(5.5)
58
59Deprecated: zend_number_or_string(): Passing null to parameter #1 ($param) of type string|int|float is deprecated in %s on line %d
60int(0)
61int(0)
62int(1)
63string(8) "ToString"
64zend_string_or_object(): Argument #1 ($param) must be of type object|string, array given
65zend_number_or_string(): Argument #1 ($param) must be of type string|int|float, Foo given
66string(6) "string"
67int(1)
68float(5.5)
69NULL
70int(0)
71int(1)
72string(8) "ToString"
73zend_number_or_string_or_null(): Argument #1 ($param) must be of type string|int|float|null, array given
74zend_number_or_string_or_null(): Argument #1 ($param) must be of type string|int|float|null, Foo given
75