1--TEST--
2Test Z_PARAM_OBJ_OF_CLASS_OR_STR() and Z_PARAM_OBJ_OF_CLASS_OR_STR_OR_NULL
3--SKIPIF--
4<?php
5if (!extension_loaded('zend-test')) die('skip zend-test extension not loaded');
6?>
7--FILE--
8<?php
9
10class Foo {}
11class ToString {
12    public function __toString() {
13        return "ToString";
14    }
15}
16
17var_dump(zend_string_or_stdclass("string"));
18var_dump(zend_string_or_stdclass(1));
19var_dump(zend_string_or_stdclass(null));
20var_dump(zend_string_or_stdclass(new stdClass()));
21var_dump(zend_string_or_stdclass(new ToString()));
22
23try {
24    zend_string_or_stdclass([]);
25} catch (TypeError $exception) {
26    echo $exception->getMessage() . "\n";
27}
28
29try {
30    zend_string_or_stdclass(new Foo());
31} catch (TypeError $exception) {
32    echo $exception->getMessage() . "\n";
33}
34
35var_dump(zend_string_or_stdclass_or_null("string"));
36var_dump(zend_string_or_stdclass_or_null(1));
37var_dump(zend_string_or_stdclass_or_null(null));
38var_dump(zend_string_or_stdclass_or_null(new stdClass()));
39var_dump(zend_string_or_stdclass_or_null(new ToString()));
40
41try {
42    zend_string_or_stdclass_or_null([]);
43} catch (TypeError $exception) {
44    echo $exception->getMessage() . "\n";
45}
46
47try {
48    zend_string_or_stdclass_or_null(new Foo());
49} catch (TypeError $exception) {
50    echo $exception->getMessage() . "\n";
51}
52
53?>
54--EXPECT--
55string(6) "string"
56string(1) "1"
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