Skip to content

Instantly share code, notes, and snippets.

@juareznjunior
Created June 21, 2011 19:59
Show Gist options
  • Save juareznjunior/1038736 to your computer and use it in GitHub Desktop.
Save juareznjunior/1038736 to your computer and use it in GitHub Desktop.
<?php
$start = microtime(true);
class Post {
private $_data = array(
'id'=>NULL
,'title'=>NULL
,'status'=>NULL
,'blog'=>NULL
,'comments'=>NULL
,'pubdate'=>NULL
);
public function __construct() {}
public function __get($p) {
if (self::_dataKeyExists($p)) {
return $this->_data[$p];
}
}
public function __set($p,$v) {
if (self::_dataKeyExists($p)) {
$this->_data[$p] = $v;
}
}
public function dump() {
print_r($this->_data);
}
private function _dataKeyExists($k) {
return (bool) array_key_exists($k,$this->_data);
}
}
$post = new Post();
$post->id = 2;
$post->status = 'Ativo';
$post->dump();
echo microtime(true) - $start;
echo PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment