Guest User

Untitled

a guest
Jul 22nd, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. <?php
  2.  
  3. header('Content-type:text/plain; charset=utf-8;');
  4.  
  5. class ModelAbstract
  6. {
  7. public function __call($name, $arguments)
  8. {
  9. $prefix = substr($name, 0, 3);
  10. $column_name = strtolower(str_replace(' ', '_', preg_replace('/(?!^)[A-Z]{2,}(?=[A-Z][a-z])|[A-Z][a-z]/', ' $0', substr($name, 3))));
  11. if ($prefix == 'get')
  12. {
  13. // getter
  14. return $this->$column_name;
  15. }else if($prefix == 'set'){
  16. // setter
  17. $this->$column_name = $arguments[0];
  18. return $this;
  19. }
  20. }
  21. }
  22.  
  23. class User extends ModelAbstract
  24. {
  25. protected $_id = 0;
  26. protected $_username = '';
  27. protected $_password = '';
  28. }
  29.  
  30. class UserNormal
  31. {
  32. private $id = 0;
  33. private $username = '';
  34. private $password = '';
  35.  
  36. public function setId($value)
  37. {
  38. $this->id = $value;
  39. return $this;
  40. }
  41.  
  42. public function getId()
  43. {
  44. return $this->id;
  45. }
  46.  
  47. public function setUsername($value)
  48. {
  49. $this->username = $value;
  50. return $this;
  51. }
  52.  
  53. public function getUsername()
  54. {
  55. return $this->username;
  56. }
  57.  
  58. public function setPassword($value)
  59. {
  60. $this->password = $value;
  61. return $this;
  62. }
  63.  
  64. public function getPassword()
  65. {
  66. return $this->password;
  67. }
  68. }
  69.  
  70. $_s = microtime(true);
  71. for($i=0;$i<10;$i++)
  72. {
  73. $user_model = new User();
  74. $user_model->setUsername('username')
  75. ->setPassword('password');
  76. }
  77. $_e = microtime(true);
  78.  
  79. echo number_format(($_e - $_s), 5)." second\n\n";
  80.  
  81.  
  82. $_s = microtime(true);
  83. for($i=0;$i<10;$i++)
  84. {
  85. $user_model = new UserNormal();
  86. $user_model->setUsername('username')
  87. ->setPassword('password');
  88. }
  89. $_e = microtime(true);
  90.  
  91. echo number_format(($_e - $_s), 5)." second";
Add Comment
Please, Sign In to add comment