I have two user tables in my database (parent-child). I want to have some functions to check user existence, return a user list etc, but I also want to have functions for user specific (operating on the object called on) actions such as get name, get email, reset password etc.
At the moment I have this:
<?php
class User {
public $id;
public $email;
private $password;
public $accountType;
public function __construct(...) {
...
}
// ####### GLOBAL ####### (Static)
// Searches for user by email
public function findUser($email) {
...
}
// ####### GETTERS #######
public function getID() {
...
}
...
// ####### SETTERS #######
public function setID() {
...
}
}
I know that in OOP I should just make the global functions static, but I'm not sure if this is what I should in PHP.
This is really up to you - there are actually no clear hard rules about how to handle "table operations" (unlike with "record operations" that everyone agrees should be methods on the instance representing the record).
Some examples:
This is a design decision that is very much up to you.