I am trying to return multiple variables from a method.
This is what I have tried so far:
This code is the method in the class:
public function getUserInfo(){
$stmt = $this->dbh->prepare("SELECT user_id FROM oopforum_users WHERE username = ?");
$stmt->bindParam(1, $this->post_data['username']);
$stmt->execute();
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$user_id = $row['user_id'];
$thumb = $row['thumbnail'];
}
return array($user_id, $thumb);
}
I attempt to place each variable in a list for use in the calling program:
session_start();
require_once('init.php');
$username = trim($_POST['username']);
// create a new object
$login = new Auth($_POST, $dbh);
if($login->validateLogin()){
$_SESSION['loggedin'] = true;
list($user_id, $thumb) = $login->getUserInfo($user_id, $thumb);
echo $user_id . ' ' . $thumb;
}
This hasn't work.
How can I return an array of multiple variables from a method within a class for use in the calling program?