3v4l.org

run code in 300+ PHP versions simultaneously
<?php class DataCollector { use setData, dataHandler; private static $CollectionData = array(); private static function collectedData( $type, $value = NULL ) { if( strtolower( $type ) === 'set' ) { $CollectionData[] = $value; var_dump($CollectionData); } elseif( strtolower( $type ) === 'get' ) return self::$CollectionData; } } trait setData { static function setData( $data ) { DataCollector::collectedData( 'set', $data ); } } trait dataHandler { static function getCollectedData() { DataCollector::collectedData( 'get' ); } } class Form { use setData {} } class Field extends Form { public function __construct( $type, $text = NULL ) { DataCollector::setData( $type ); } } class A { use setData{} public function __construct( $type, $text = NULL ) { self::setData( $type ); } } $Field1 = new Field( '1' ); $Field2 = new Field( '2' ); $A = new A( '3' ); DataCollector::setData('4'); dataHandler::setData('5'); var_dump( dataHandler::getCollectedData() );

preferences:
77.22 ms | 402 KiB | 5 Q