Skip to content

Instantly share code, notes, and snippets.

@dkhenry
Created May 15, 2012 16:10
Show Gist options
  • Save dkhenry/2702947 to your computer and use it in GitHub Desktop.
Save dkhenry/2702947 to your computer and use it in GitHub Desktop.
Example of PHP traits
trait DatabaseToObject {
public static function fromResultSet( $results) {
$retval = array();
if(!$results) {
return $retval;
}
while( $row = $results->fetchObject() ) {
$retval[] = static::construct($row);
}
return $retval;
}
}
class FileParser {
use DatabaseToObject;
public static function construct( $object ) {
$fp = new FileParser();
$fp->name = $object->name ;
$fp->code = $object->code ;
$fp->types = array();
return $fp;
}
public static function list_full( $link ) {
return FileParser::fromResultSet( $link->query(static::$fpquery));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment