How to get members level and subscription in php code

hi i would like to know how can I get the members level and subscription.

I tried this but I got some error

if (is_user_logged_in()){
$user_id = get_current_user_id();
$subscription = new M_Subscription(end(get_sub_by_user($user_id))->sub_id);
echo $subscription->sub_name();
} else {
echo 'Please register or log in to see more.';

this is the error
Fatal error: Call to undefined function get_sub_by_user() in /var/www/wp-content/themes/sitetheme/single.php on line 7

I used this code to solve above

function get_sub_by_user($user_id) {

	$member = new M_Membership( $user_id );
	if($member->has_subscription()) {
		return $member->current_subscription();
	} else {
	return false;

and it shows this error
Fatal error: Call to undefined method M_Membership::current_subscription() in /var/www/wp-content/themes/sitetheme/functiondev.php on line 262

I do want only just to get the output of name and id of the subscription level and members level.