fork download
  1. <?php
  2.  
  3. class bar {
  4. public $x = "Hello from 5.4\n";
  5. }
  6.  
  7. class foo implements ArrayAccess {
  8. public $y = 'bar';
  9.  
  10. public function bar($msg = '') {
  11. return 'From ' . $msg . "\n";
  12. }
  13.  
  14. public function offsetGet($key) {
  15. return "Accessing key $key \n";
  16. }
  17.  
  18. public function offsetSet($offset, $value) {}
  19. public function offsetExists($offset) {}
  20. public function offsetUnset($offset) {}
  21. }
  22.  
  23. $foo = 'foo';
  24. $bar = new foo;
  25.  
  26. echo (new foo())->bar('class');
  27. echo (new $foo)->bar('variable');
  28. echo (new $foo())->bar('variable w/ braces');
  29. echo (new $bar->y)->x;
  30. echo (new foo)[0];
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
From class
From variable
From variable w/ braces
Hello from 5.4
Accessing key 0