The error has nothing to do with php version. You are fetching the data as an object, but attempting to use array syntax to access it.
You were already told elsewhere what to set the default fetch mode to -
and set the default fetch mode to assoc, you are setting it to obj, which is not what you are using in the example code and is probably not what your existing code is using with the fetched data, which will require you to make even more changes to your existing code.
Programming is a writing and reading activity. You must at some point actually read the words and syntax making up the code you are using and be able to describe to yourself what they are doing.
otuatail PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ
Even if you have no specific experience with php or the PDO extension, doesn't reading the above line of code hint that you are setting something called the default fetch mode to OBJ (an abbreviation of the word object)?