fork download
  1. <?php
  2.  
  3. class A {
  4. public $property;
  5. public $propertyForB;
  6.  
  7. public function __construct() {
  8. $this->propertyForB = new B();
  9. }
  10.  
  11. public function hello() {
  12. $this->property = 'hello';
  13. return $this;
  14. }
  15.  
  16. public function world() {
  17. $this->property .= ' world';
  18. return $this->property;
  19. }
  20. }
  21.  
  22.  
  23. class B {
  24. public function helloWorld() {
  25. return 'hello world';
  26. }
  27. }
  28.  
  29.  
  30. $test = new A();
  31.  
  32. echo $test->hello()->world();
  33.  
  34. echo '<br />';
  35.  
  36. echo $test->propertyForB->helloWorld();
Success #stdin #stdout 0.02s 52480KB
stdin
Standard input is empty
stdout
hello world<br />hello world