I'm new to PHP, but not new to programming. I have a strange problem. It's such a simple thing, and I have the feeling the solution is simple also, but I tried for hours without luck.
I have a model class User which 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 right username. Except in the User class itself: when I call the function with User::byUsername('a_valid_username'), or self::, from another static function further down in the User class, the DB::fetchOne() function just returns null, no errors or exceptions.
What am I missing?
I don't see a problem inside of the byUsernam() method.
Perform
echo $username;
or
print_r( debug_backtrace() );
right at the beginning of byUsernam() to learn more of the called environment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With