I am new to PHP, but not new to programming. I have a strange problem. This is such a simple thing, and I feel the solution is simple, but I tried for hours with no luck.
I have a model class User that contains the following function:
public static function byUsername ($ username) {
$ row = DB :: fetchOne ('SELECT * FROM users WHERE username =?', $ username);
if (! is_null ($ row)) {
return new User ($ row);
}
return null;
}
It works as expected everywhere, returning a User object, given the correct username. Except for the User class itself: when I call a function with User::byUsername('a_valid_username')or self::, from another static function further in the User class, the function DB::fetchOne()simply returns nullno errors or exceptions.
What am I missing?
source
share