3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait DataCollector { static $collectionData = array(); abstract public function setData( $data ) { self::$CollectionData[] = $data; return $this; } abstract public function getCollectedData() { return self::$CollectionData; } } class Form {} class Field extends Form { use DataCollector; public function __construct( $type, $text = NULL ) { $this->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/j9Gol on line 8
Process exited with code 255.
Output for 5.3.0 - 5.3.27
Parse error: syntax error, unexpected T_STRING in /in/j9Gol on line 2
Process exited with code 255.

preferences:
181.66 ms | 1386 KiB | 53 Q