简体   繁体   中英

Trying to get property of non-object when used on object

I have some PHP that is returning an object to a variable:

                $db = new Db(); 
                $db->db_connect(); 
                $testSelectQuery = $db->db_select('SELECT * FROM test');
                //$dbValue = $testSelectQuery[0]->testcol;
                $test = $testSelectQuery[0];
                FB::log($test);

Here is the output of $test:

Object {idtest: "1", testcol: "from db"}

Now when I try to echo one of the columns:

echo $test->testcol

I get an error:

Notice: Trying to get property of non-object

It was just defined as an object in the output. What am I doing wrong and how do I fix it?

Edit: vardump($test) results in: array(2) { ["idtest"]=> string(1) "1" ["testcol"]=> string(7) "from db" }

It looks like $test is an associative array

Access it like this:

echo $test['testcol'];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM