3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait DataCollector { protected static $CollectionData = array(); static function setData( $data ) { self::$CollectionData[] = $data; } static function getCollectedData() { return self::$CollectionData; } } class dataHandler { use DataCollector } class Form {} class Field extends Form { use DataCollector { getCollectedData as private; } public function __construct( $type, $text = NULL ) { self::setData( $type ); } } $Field1 = new Field( 'text' ); $Field2 = new Field( 'html', 'hello' ); var_dump( dataHandler::getCollectedData() );
Output for 5.4.0 - 5.4.17
Parse error: syntax error, unexpected '}', expecting ',' or ';' or '{' in /in/9e3Vq on line 16
Process exited with code 255.
Output for 5.3.0 - 5.3.27
Parse error: syntax error, unexpected T_STRING in /in/9e3Vq on line 2
Process exited with code 255.

preferences:
171.2 ms | 1395 KiB | 53 Q