<?php
class bar {
public $x = "Hello from 5.4\n";
}
class foo implements ArrayAccess {
public $y = 'bar';
public function bar($msg = '') {
return 'From ' . $msg . "\n";
}
public function offsetGet($key) {
return "Accessing key $key \n";
}
public function offsetSet($offset, $value) {}
public function offsetExists($offset) {}
public function offsetUnset($offset) {}
}
$foo = 'foo';
$bar = new foo;
echo (new foo())->bar('class');
echo (new $foo)->bar('variable');
echo (new $foo())->bar('variable w/ braces');
echo (new $bar->y)->x;
echo (new foo)[0];
PD9waHAKCmNsYXNzIGJhciB7CglwdWJsaWMgJHggPSAiSGVsbG8gZnJvbSA1LjRcbiI7Cn0KCmNsYXNzIGZvbyBpbXBsZW1lbnRzIEFycmF5QWNjZXNzIHsKCXB1YmxpYyAkeSA9ICdiYXInOwoJCglwdWJsaWMgZnVuY3Rpb24gYmFyKCRtc2cgPSAnJykgewoJCXJldHVybiAnRnJvbSAnIC4gJG1zZyAuICJcbiI7Cgl9CgkKCXB1YmxpYyBmdW5jdGlvbiBvZmZzZXRHZXQoJGtleSkgewoJCXJldHVybiAiQWNjZXNzaW5nIGtleSAka2V5IFxuIjsKCX0KCQoJcHVibGljIGZ1bmN0aW9uIG9mZnNldFNldCgkb2Zmc2V0LCAkdmFsdWUpIHt9CglwdWJsaWMgZnVuY3Rpb24gb2Zmc2V0RXhpc3RzKCRvZmZzZXQpIHt9CglwdWJsaWMgZnVuY3Rpb24gb2Zmc2V0VW5zZXQoJG9mZnNldCkge30KfQoKJGZvbyA9ICdmb28nOwokYmFyID0gbmV3IGZvbzsKCmVjaG8gKG5ldyBmb28oKSktPmJhcignY2xhc3MnKTsKZWNobyAobmV3ICRmb28pLT5iYXIoJ3ZhcmlhYmxlJyk7CmVjaG8gKG5ldyAkZm9vKCkpLT5iYXIoJ3ZhcmlhYmxlIHcvIGJyYWNlcycpOwplY2hvIChuZXcgJGJhci0+eSktPng7CmVjaG8gKG5ldyBmb28pWzBdOw==