I just discovered that empty() does not work when passing data from an object. Why is that?
This is my code:
// This works
$description = $store->description;
if (!empty($description) )
echo $description;
//This is not working
if (!empty($store->description) )
echo $store->description;
UPDATE
Added extra code for context.
// 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...
)
)
You should read the docs for
empty(). There is an explanation of why empty might fail in the comments.For example you will get this error if
descriptionis a private property, you have set up a magic__getfunction without the magic__issetfunction.So this will fail:
and this will succeed: