indirect_method_call_002.phpt 714 B

1234567891011121314151617181920212223242526272829303132333435
  1. --TEST--
  2. Indirect method call with chaining
  3. --FILE--
  4. <?php
  5. class foo {
  6. public $x = 'testing';
  7. public function bar() {
  8. return "foo";
  9. }
  10. public function baz() {
  11. return new self;
  12. }
  13. static function xyz() {
  14. }
  15. }
  16. var_dump((new foo())->bar()); // string(3) "foo"
  17. var_dump((new foo())->baz()->x); // string(7) "testing"
  18. var_dump((new foo())->baz()->baz()->bar()); // string(3) "foo"
  19. var_dump((new foo())->xyz()); // NULL
  20. (new foo())->www();
  21. ?>
  22. --EXPECTF--
  23. string(3) "foo"
  24. string(7) "testing"
  25. string(3) "foo"
  26. NULL
  27. Fatal error: Uncaught Error: Call to undefined method foo::www() in %s:%d
  28. Stack trace:
  29. #0 {main}
  30. thrown in %s on line %d