xref: /php-src/Zend/tests/objects/objects_022.phpt (revision 275f63e7)
1--TEST--
2Testing 'self', 'parent' as type-hint
3--FILE--
4<?php
5
6interface iTest { }
7
8class baz implements iTest {}
9
10class bar { }
11
12class foo extends bar {
13    public function testFoo(self $obj) {
14        var_dump($obj);
15    }
16    public function testBar(parent $obj) {
17        var_dump($obj);
18    }
19    public function testBaz(iTest $obj) {
20        var_dump($obj);
21    }
22}
23
24$foo = new foo;
25$foo->testFoo(new foo);
26$foo->testBar(new bar);
27$foo->testBaz(new baz);
28$foo->testFoo(new stdClass); // Recoverable fatal error
29
30?>
31--EXPECTF--
32object(foo)#%d (0) {
33}
34object(bar)#%d (0) {
35}
36object(baz)#%d (0) {
37}
38
39Fatal error: Uncaught TypeError: foo::testFoo(): Argument #1 ($obj) must be of type foo, stdClass given, called in %s:%d
40Stack trace:
41#0 %s(%d): foo->testFoo(Object(stdClass))
42#1 {main}
43  thrown in %s on line %d
44