3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait DataCollector { private static function getCollectedData() { return self::collectedData( 'get' ); } private static function collectedData( $type, $value = NULL ) { static $CollectionData = array(); if( strtolower( $type ) === 'set' ) { $CollectionData[] = $value; var_dump($CollectionData); } elseif( strtolower( $type ) === 'get' ) return $CollectionData; } static function setCollectedData( $data ) { self::collectedData( 'set' , $data ); } } class dataHandler { use DataCollector { getCollectedData as public; } } $a = new dataHandler(); $a::setCollectedData( 'bob' ); dataHandler::setCollectedData( 'a' ); var_dump('collectedData' , dataHandler::getCollectedData() );

preferences:
45.03 ms | 402 KiB | 5 Q