Skip to content

Instantly share code, notes, and snippets.

@omerucel
Created February 14, 2011 06:02
Show Gist options
  • Save omerucel/825546 to your computer and use it in GitHub Desktop.
Save omerucel/825546 to your computer and use it in GitHub Desktop.
<?php
header('Content-type:text/plain; charset=utf-8;');
class ModelAbstract
{
public function __call($name, $arguments)
{
$prefix = substr($name, 0, 3);
$column_name = strtolower(str_replace(' ', '_', preg_replace('/(?!^)[A-Z]{2,}(?=[A-Z][a-z])|[A-Z][a-z]/', ' $0', substr($name, 3))));
if ($prefix == 'get')
{
// getter
return $this->$column_name;
}else if($prefix == 'set'){
// setter
$this->$column_name = $arguments[0];
return $this;
}
}
}
class User extends ModelAbstract
{
protected $_id = 0;
protected $_username = '';
protected $_password = '';
}
class UserNormal
{
private $id = 0;
private $username = '';
private $password = '';
public function setId($value)
{
$this->id = $value;
return $this;
}
public function getId()
{
return $this->id;
}
public function setUsername($value)
{
$this->username = $value;
return $this;
}
public function getUsername()
{
return $this->username;
}
public function setPassword($value)
{
$this->password = $value;
return $this;
}
public function getPassword()
{
return $this->password;
}
}
$_s = microtime(true);
for($i=0;$i<10;$i++)
{
$user_model = new User();
$user_model->setUsername('username')
->setPassword('password');
}
$_e = microtime(true);
echo number_format(($_e - $_s), 5)." second\n\n";
$_s = microtime(true);
for($i=0;$i<10;$i++)
{
$user_model = new UserNormal();
$user_model->setUsername('username')
->setPassword('password');
}
$_e = microtime(true);
echo number_format(($_e - $_s), 5)." second";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment