xref: /PHP-5.5/Zend/tests/objects_022.phpt (revision e4c76641)
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); // Catchable fatal error
29
30?>
31--EXPECTF--
32object(foo)#%d (0) {
33}
34object(bar)#%d (0) {
35}
36object(baz)#%d (0) {
37}
38
39Catchable fatal error: Argument 1 passed to foo::testFoo() must be an instance of foo, instance of stdClass given, called in %s on line %d and defined in %s on line %d
40