xref: /PHP-8.2/Zend/tests/str_or_obj_zpp.phpt (revision 74859783)
1--TEST--
2Test Z_PARAM_OBJ_OR_STR() and Z_PARAM_OBJ_OR_STR_OR_NULL
3--EXTENSIONS--
4zend_test
5--FILE--
6<?php
7
8class Foo {}
9
10var_dump(zend_string_or_object("string"));
11var_dump(zend_string_or_object(1));
12var_dump(zend_string_or_object(null));
13var_dump(zend_string_or_object(new stdClass()));
14var_dump(zend_string_or_object(new Foo()));
15
16try {
17    zend_string_or_object([]);
18} catch (TypeError $exception) {
19    echo $exception->getMessage() . "\n";
20}
21
22var_dump(zend_string_or_object_or_null("string"));
23var_dump(zend_string_or_object_or_null(1));
24var_dump(zend_string_or_object_or_null(null));
25var_dump(zend_string_or_object_or_null(new stdClass()));
26var_dump(zend_string_or_object_or_null(new Foo()));
27
28try {
29    zend_string_or_object_or_null([]);
30} catch (TypeError $exception) {
31    echo $exception->getMessage() . "\n";
32}
33
34?>
35--EXPECTF--
36string(6) "string"
37string(1) "1"
38
39Deprecated: zend_string_or_object(): Passing null to parameter #1 ($param) of type object|string is deprecated in %s on line %d
40string(0) ""
41object(stdClass)#1 (0) {
42}
43object(Foo)#1 (0) {
44}
45zend_string_or_object(): Argument #1 ($param) must be of type object|string, array given
46string(6) "string"
47string(1) "1"
48NULL
49object(stdClass)#2 (0) {
50}
51object(Foo)#2 (0) {
52}
53zend_string_or_object_or_null(): Argument #1 ($param) must be of type object|string|null, array given
54