xref: /PHP-8.2/Zend/tests/010.phpt (revision c98d4769)
1--TEST--
2get_parent_class() tests
3--FILE--
4<?php
5
6interface i {
7    function test();
8}
9
10class foo implements i {
11    function test() {
12        var_dump(get_parent_class());
13    }
14}
15
16class bar extends foo {
17    function test_bar() {
18        var_dump(get_parent_class());
19    }
20}
21
22$bar = new bar;
23$foo = new foo;
24
25$foo->test();
26$bar->test();
27$bar->test_bar();
28
29var_dump(get_parent_class($bar));
30var_dump(get_parent_class($foo));
31var_dump(get_parent_class("bar"));
32var_dump(get_parent_class("foo"));
33var_dump(get_parent_class("i"));
34
35try {
36    get_parent_class("");
37} catch (TypeError $exception) {
38    echo $exception->getMessage() . "\n";
39}
40
41try {
42    get_parent_class("[[[[");
43} catch (TypeError $exception) {
44    echo $exception->getMessage() . "\n";
45}
46
47try {
48    get_parent_class(" ");
49} catch (TypeError $exception) {
50    echo $exception->getMessage() . "\n";
51}
52
53var_dump(get_parent_class(new stdclass));
54
55try {
56    get_parent_class(array());
57} catch (TypeError $exception) {
58    echo $exception->getMessage() . "\n";
59}
60
61try {
62    get_parent_class(1);
63} catch (TypeError $exception) {
64    echo $exception->getMessage() . "\n";
65}
66
67echo "Done\n";
68?>
69--EXPECT--
70bool(false)
71bool(false)
72string(3) "foo"
73string(3) "foo"
74bool(false)
75string(3) "foo"
76bool(false)
77bool(false)
78get_parent_class(): Argument #1 ($object_or_class) must be an object or a valid class name, string given
79get_parent_class(): Argument #1 ($object_or_class) must be an object or a valid class name, string given
80get_parent_class(): Argument #1 ($object_or_class) must be an object or a valid class name, string given
81bool(false)
82get_parent_class(): Argument #1 ($object_or_class) must be an object or a valid class name, array given
83get_parent_class(): Argument #1 ($object_or_class) must be an object or a valid class name, int given
84Done
85