Advertisement
Guest User

Untitled

a guest
Jul 30th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. users.php
  2.  
  3. class Users
  4. {
  5. private $id = null;
  6.  
  7. private $login = null;
  8. private $password = null;
  9.  
  10. public function __construct($login, $password)
  11. {
  12. $this->login = $login;
  13. $this->password = $password;
  14. }
  15.  
  16. // All Setters && Getters for all cells of db
  17. // a.g public function SetLogin; public function GetLogin
  18.  
  19. static public function getInstance($id)
  20. {
  21. $row = "SELECT * FROM `users` WHERE `id` = '{$id}' ";
  22. if($row){
  23. $obj = new Users($row['login'], $row['password']);
  24. $obj->setId($row['id']);
  25. return $obj;
  26. }
  27. }
  28. }
  29.  
  30. $this->password = isset($array['password']) ? $array['password'] : null;
  31.  
  32. class Users
  33. {
  34. private $id = null;
  35.  
  36. private $login = null;
  37. private $password = null;
  38.  
  39. public function __construct(...$fields)
  40. {
  41. $this->login = $fields[0];
  42. $this->password = $fields[1];
  43. }
  44. ...
  45. }
  46. $user = new Users('hello', 'world');
  47. echo "<pre>";
  48. print_r($user);
  49.  
  50. class Users
  51. {
  52. private $id = null;
  53.  
  54. private $login = null;
  55. private $password = null;
  56.  
  57. public function __construct($fields)
  58. {
  59. foreach($fields as $key => $value) {
  60. $this->$key = $value;
  61. }
  62. }
  63. // ...
  64. }
  65. $user = new Users(['login' => 'hello', 'password' => 'world']);
  66. echo "<pre>";
  67. print_r($user);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement