PHP PDO试图获取非对象的属性

I'm getting Notice: Trying to get property of non-object in when I'm trying to

foreach ($query->fetch(PDO::FETCH_OBJ) as $row) {
        echo $row->id_users;
        echo $row->username;
        echo $row->password;
        echo $row->email;
    }

When I use print_r($query->fetch(PDO::FETCH_OBJ)) i'm getting

Class Object ( [id_users] => 1 [username] => test [password] => test [email] => test )

Typically to iterate througha recordset you would do something along these lines.

while( $row = $query->fetch(PDO::FETCH_OBJ) ){
        echo $row->id_users;
        echo $row->username;
        echo $row->password;
        echo $row->email;
}