3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php interface Element { /** * Constructor function. Must pass existing config, or leave as * is for new element, where the default will be used instead. * * @param array $config Element configuration. */ public function __construct( $config = [] ); /** * Get the definition of the Element. * * @return array An array with 'title', 'description' and 'type' */ public static function get_definition(); /** * Get Element config variable. * * @return array Associative array of Element Config. */ public function get_config(); /** * Set Element config variable. * * @param array $config New configuration variable. * * @return void */ public function set_config( $config ); } abstract class Base implements Element { /** * Element configuration variable * * @var array */ protected $config = []; /** * Get Element config variable. * * @return array Associative array of Element Config. */ public function get_config() { return $this->config; } /** * Create an eForm Element instance * * @param array $config Element config. */ public function __construct( $config = [] ) { $this->set_config( $config ); } } class MyElement extends Base { public static function get_definition() { return [ 'type' => 'MyElement', ]; } public function set_config( $config ) { // Do something here $this->config = $config; } } $element = new MyElement( [ 'foo' => 'bar', ] ); print_r( $element->get_config() );
Output for 5.4.0 - 5.6.40, hhvm-3.10.1 - 3.22.0, 7.0.0 - 7.3.5
Array ( [foo] => bar )
Output for 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/8NqqW on line 9
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/8NqqW on line 9
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING in /in/8NqqW on line 2
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING in /in/8NqqW on line 2
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/8NqqW on line 2
Process exited with code 255.