3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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 ); } } $Field1 = new Field( 'text' ); var_dump( $Field1->getCollectedData() ); $Field2 = new Field( 'html', 'hello' ); var_dump( $Field2->getCollectedData() );
Output for 7.0.0 - 7.1.0
Fatal error: Uncaught Error: Access to undeclared static property: Field::$CollectionData in /in/Xjt3n:6 Stack trace: #0 /in/Xjt3n(20): Field::setData('text') #1 /in/Xjt3n(24): Field->__construct('text') #2 {main} thrown in /in/Xjt3n on line 6
Process exited with code 255.
Output for hhvm-3.12.0
Fatal error: Uncaught Error: Invalid static property access: Field::CollectionData in /in/Xjt3n:6 Stack trace: #0 /in/Xjt3n(20): Field::setData() #1 /in/Xjt3n(24): Field->__construct() #2 {main}
Process exited with code 255.
Output for hhvm-3.10.0
Fatal error: Invalid static property access: Field::CollectionData in /in/Xjt3n on line 6
Process exited with code 255.
Output for 5.4.0 - 5.6.28
Fatal error: Access to undeclared static property: Field::$CollectionData in /in/Xjt3n on line 6
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected T_STRING in /in/Xjt3n on line 2
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_STRING in /in/Xjt3n on line 2
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/Xjt3n on line 2
Process exited with code 255.