簡體   English   中英

在對象上使用時嘗試獲取非對象的屬性

[英]Trying to get property of non-object when used on object

我有一些將對象返回到變量的PHP:

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

這是$ test的輸出:

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

現在,當我嘗試回顯其中一列時:

echo $test->testcol

我收到一個錯誤:

Notice: Trying to get property of non-object

它只是在輸出中定義為對象。 我在做什么錯,我該如何解決?

編輯:vardump($ test)結果為: array(2) { ["idtest"]=> string(1) "1" ["testcol"]=> string(7) "from db" }

看起來$test是一個關聯數組

像這樣訪問它:

echo $test['testcol'];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM