- var_dump: documentation ( source)
- strtolower: documentation ( source)
<?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() );