3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Container { protected $target; protected $className; protected $methods = array(); public function __construct( $target ) { $this->target = $target; } public function attach( $name, $method ) { if ( !$this->className ) { $this->className = get_class( $this->target ); } $binded = Closure::bind( $method, $this->target, $this->className ); $this->methods[$name] = $binded; } public function __call( $name, $arguments ) { if ( array_key_exists( $name, $this->methods ) ) { return call_user_func_array( $this->methods[$name] , $arguments ); } if ( method_exists( $this->target, $name ) ) { return call_user_func_array( array( $this->target, $name ), $arguments ); } } } class Foo { private $bar = 'payload'; }; $foobar = new Foo; // you initial object $instance = new Container( $foobar ); $func = function ( $param ) { return 'Get ' . $this->bar . ' and ' . $param; }; $instance->attach('test', $func); // setting up the whole thing echo $instance->test('lorem ipsum'); // 'Get payload and lorem ipsum'
Output for git.master, git.master_jit, rfc.property-hooks
Get payload and lorem ipsum

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
43.82 ms | 401 KiB | 8 Q