Advertisement
Guest User

Untitled

a guest
Jul 30th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 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. class Users
  31. {
  32. private $id = null;
  33.  
  34. private $login = null;
  35. private $password = null;
  36.  
  37. public function __construct(...$fields)
  38. {
  39. $this->login = $fields[0];
  40. $this->password = $fields[1];
  41. }
  42. ...
  43. }
  44. $user = new Users('hello', 'world');
  45. echo "<pre>";
  46. print_r($user);
  47.  
  48. class Users
  49. {
  50. private $id = null;
  51.  
  52. private $login = null;
  53. private $password = null;
  54.  
  55. public function __construct($fields)
  56. {
  57. foreach($fields as $key => $value) {
  58. $this->$key = $value;
  59. }
  60. }
  61. // ...
  62. }
  63. $user = new Users(['login' => 'hello', 'password' => 'world']);
  64. echo "<pre>";
  65. print_r($user);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement