Why is the function getUserID in the User class defined as static?

The function getUserID in the User class is defined as static because it does not rely on any instance-specific data or properties of the User class. By defining it as static, it can be called without needing to create an instance of the User class, making it more convenient for accessing the user ID.

class User {
    private static $userID = 123;

    public static function getUserID() {
        return self::$userID;
    }
}

// To call the getUserID function
$userID = User::getUserID();
echo $userID;