3v4l.org

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

preferences:
179.64 ms | 1395 KiB | 53 Q