objects_022.phpt 815 B

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