ns_072.phpt 621 B

12345678910111213141516171819202122232425262728293031323334353637
  1. --TEST--
  2. Testing parameter type-hinted with interface
  3. --FILE--
  4. <?php
  5. namespace foo;
  6. interface foo {
  7. }
  8. class bar {
  9. public function __construct(foo $x = NULL) {
  10. var_dump($x);
  11. }
  12. }
  13. class test implements foo {
  14. }
  15. new bar(new test);
  16. new bar(null);
  17. new bar(new \stdclass);
  18. ?>
  19. --EXPECTF--
  20. object(foo\test)#%d (0) {
  21. }
  22. NULL
  23. Fatal error: Uncaught TypeError: Argument 1 passed to foo\bar::__construct() must implement interface foo\foo or be null, instance of stdClass given, called in %s on line %d and defined in %s:%d
  24. Stack trace:
  25. #0 %s(%d): foo\bar->__construct(Object(stdClass))
  26. #1 {main}
  27. thrown in %s on line %d