3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php trait DataCollector { static $collectionData = array(); abstract public function setData( $data ) { self::$CollectionData[] = $data; } abstract public function getCollectedData() { return self::$CollectionData; } } class Form {} class Field extends Form { use DataCollector; public function __construct( $type, $text = NULL ) { self::setData( $type ); } } $Field1 = new Field( 'text' ); var_dump( $Field1->getCollectedData() ); $Field2 = new Field( 'html', 'hello' ); var_dump( $Field2->getCollectedData() );
Output for 5.4.0 - 5.4.17
Fatal error: Abstract function DataCollector::setData() cannot contain body in /in/S823N on line 7
Process exited with code 255.
Output for 5.3.0 - 5.3.27
Parse error: syntax error, unexpected T_STRING in /in/S823N on line 2
Process exited with code 255.