3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait DataCollector { private $collectionData = array(); final private function setData( $data ) { $this->CollectionData[] = $data; return $this; } public function getCollectedData() { return $this->CollectionData; } } class Form {} class Field extends Form { use DataCollector; public function __construct( $type, $text = NULL ) { $this->setData( $type )->setData( $text ); } } $Field1 = new Field( 'text' ); var_dump( $Field1->getCollectedData() ); $Field2 = new Field( 'html', 'hello' ); var_dump( $Field2->getCollectedData() );

preferences:
54.76 ms | 402 KiB | 5 Q