xref: /php-src/Zend/tests/010.phpt (revision 11262320)
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($this));
19    }
20}
21
22$bar = new bar;
23$foo = new foo;
24
25set_error_handler(function ($severity, $message, $file, $line) {
26    throw new Exception($message);
27});
28try {
29    $foo->test();
30} catch (Exception $e) {
31    echo $e->getMessage() . "\n";
32}
33set_error_handler(null);
34
35$foo->test();
36$bar->test();
37$bar->test_bar();
38
39var_dump(get_parent_class($bar));
40var_dump(get_parent_class($foo));
41var_dump(get_parent_class("bar"));
42var_dump(get_parent_class("foo"));
43var_dump(get_parent_class("i"));
44
45try {
46    get_parent_class("");
47} catch (TypeError $exception) {
48    echo $exception->getMessage() . "\n";
49}
50
51try {
52    get_parent_class("[[[[");
53} catch (TypeError $exception) {
54    echo $exception->getMessage() . "\n";
55}
56
57try {
58    get_parent_class(" ");
59} catch (TypeError $exception) {
60    echo $exception->getMessage() . "\n";
61}
62
63var_dump(get_parent_class(new stdclass));
64
65try {
66    get_parent_class(array());
67} catch (TypeError $exception) {
68    echo $exception->getMessage() . "\n";
69}
70
71try {
72    get_parent_class(1);
73} catch (TypeError $exception) {
74    echo $exception->getMessage() . "\n";
75}
76
77echo "Done\n";
78?>
79--EXPECTF--
80Calling get_parent_class() without arguments is deprecated
81
82Deprecated: Calling get_parent_class() without arguments is deprecated in %s on line %d
83bool(false)
84
85Deprecated: Calling get_parent_class() without arguments is deprecated in %s on line %d
86bool(false)
87string(3) "foo"
88string(3) "foo"
89bool(false)
90string(3) "foo"
91bool(false)
92bool(false)
93get_parent_class(): Argument #1 ($object_or_class) must be an object or a valid class name, string given
94get_parent_class(): Argument #1 ($object_or_class) must be an object or a valid class name, string given
95get_parent_class(): Argument #1 ($object_or_class) must be an object or a valid class name, string given
96bool(false)
97get_parent_class(): Argument #1 ($object_or_class) must be an object or a valid class name, array given
98get_parent_class(): Argument #1 ($object_or_class) must be an object or a valid class name, int given
99Done
100