我剛剛發現從對象傳遞數據時empty()
不起作用。這是爲什麼?從對象傳遞數據時,empty()不起作用。爲什麼?
這是我的代碼:
// This works
$description = $store->description;
if (!empty($description))
echo $description;
//This is not working
if (!empty($store->description))
echo $store->description;
UPDATE
增加了對上下文的額外代碼。
// At the top of my PHP file I have this code
$store = Factory::new_store_obj($id);
// To controll that I got content, I can test by printing object
echo '<pre>';
print_r($store);
echo '</pre>';
//output
Store Object
(
[data:Store:private] => Array
(
[name] => Lacrosse
[street1] => Bygdøy Allé 54
[street2] =>
[zipcode] => 0265
[city] => Oslo
[country] => Norway
[phone] => 22441100
[fax] =>
[email] =>
[opening_hours] =>
[keywords] =>
[description] => Lacrosse er en bla bla bla...
)
)
它的工作原理。我嘗試了我的自我。問題在別的地方。 – Shoe 2011-04-08 15:26:52
'$ item-> description'的內容是什麼?將它分配給'$ description'時它有什麼不同? – 2011-04-08 15:27:48
你可以發佈額外的上下文嗎?也就是說,如何創建'$ item','$ description'是什麼類型,您使用的是哪個版本的PHP,並且它在「不工作」時是語法錯誤? – 2011-04-08 15:35:34