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