1--TEST--
2Test Z_PARAM_OBJ_OF_CLASS_OR_STR() and Z_PARAM_OBJ_OF_CLASS_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_string_or_stdclass("string"));
16var_dump(zend_string_or_stdclass(1));
17var_dump(zend_string_or_stdclass(null));
18var_dump(zend_string_or_stdclass(new stdClass()));
19var_dump(zend_string_or_stdclass(new ToString()));
20
21try {
22    zend_string_or_stdclass([]);
23} catch (TypeError $exception) {
24    echo $exception->getMessage() . "\n";
25}
26
27try {
28    zend_string_or_stdclass(new Foo());
29} catch (TypeError $exception) {
30    echo $exception->getMessage() . "\n";
31}
32
33var_dump(zend_string_or_stdclass_or_null("string"));
34var_dump(zend_string_or_stdclass_or_null(1));
35var_dump(zend_string_or_stdclass_or_null(null));
36var_dump(zend_string_or_stdclass_or_null(new stdClass()));
37var_dump(zend_string_or_stdclass_or_null(new ToString()));
38
39try {
40    zend_string_or_stdclass_or_null([]);
41} catch (TypeError $exception) {
42    echo $exception->getMessage() . "\n";
43}
44
45try {
46    zend_string_or_stdclass_or_null(new Foo());
47} catch (TypeError $exception) {
48    echo $exception->getMessage() . "\n";
49}
50
51?>
52--EXPECTF--
53string(6) "string"
54string(1) "1"
55
56Deprecated: zend_string_or_stdclass(): Passing null to parameter #1 ($param) of type string is deprecated in %s on line %d
57string(0) ""
58object(stdClass)#1 (0) {
59}
60string(8) "ToString"
61zend_string_or_stdclass(): Argument #1 ($param) must be of type stdClass|string, array given
62zend_string_or_stdclass(): Argument #1 ($param) must be of type stdClass|string, Foo given
63string(6) "string"
64string(1) "1"
65NULL
66object(stdClass)#1 (0) {
67}
68string(8) "ToString"
69zend_string_or_stdclass_or_null(): Argument #1 ($param) must be of type stdClass|string|null, array given
70zend_string_or_stdclass_or_null(): Argument #1 ($param) must be of type stdClass|string|null, Foo given
71