heisenberg
heisenberg

Reputation: 73

access to object arrays

How can i access ["password"] in this object?

object(DB)#2 (5) {
  ["_pdo":"DB":private]=>
  object(PDO)#3 (0) {}

  ["_query":"DB":private]=>
  object(PDOStatement)#5 (1) {
    ["queryString"]=>
    string(38) "SELECT * FROM users WHERE username = ?"
  }


  ["_error":"DB":private]=>
  bool(false)
  ["_results":"DB":private]=>
  array(1) {
    [0]=>
    object(stdClass)#6 (7) {
      ["id"]=>
      string(2) "13"
      ["username"]=>
      string(4) "amir"
      ["password"]=>
      string(64) "f7b976c547b94337793e5b822126e211337c232dc1a9a30bd4f42d7880ec1031"
      ["salt"]=>
      string(25) "j���
Ҡ??9Ek �bD���"
      ["name"]=>
      string(4) "amir"
      ["joined"]=>
      string(19) "2019-07-28 05:54:46"
      ["group"]=>
      string(1) "1"
    }
  }
  ["_count":"DB":private]=>
  int(1)
}

I have tried this :

($this->data()->password === Hash::make($password, $this->data()->salt))

but it doesnt work... . i know i should access object(stdClass)#6 (7) first but i dont know how. this method validate the data :

public function find($user = null) 
    {
        if ($user) {
            $field = (is_numeric($user)) ? 'id' : 'username';
            $data = $this->_db->get('users', array($field, '=', $user));

            if ($data->count()) {
                $this->_data = $data;
                return true;
            }
        }
        return false;
    }

Upvotes: 0

Views: 32

Answers (1)

heisenberg
heisenberg

Reputation: 73

i found the answer : i should use

$this->_data = $data->results()[0];

instead of

$this->_data = $data;

to have access to object(stdClass)

Upvotes: 1

Related Questions