Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4254952
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:09:12+00:00 2026-05-21T05:09:12+00:00

I just discovered that empty() does not work when passing data from an object.

  • 0

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...
        )
)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T05:09:13+00:00Added an answer on May 21, 2026 at 5:09 am

    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 description is a private property, you have set up a magic __get function without the magic __isset function.

    So this will fail:

    class MyClass {
        private $foo = 'foo';
        public function __get($var) { return $this->$var; }
    }
    
    $inst = new MyClass;
    if(empty($inst->foo))
    {
        print "empty";
    }
    else
    {
        print "full";
    }
    

    and this will succeed:

    class MyClass {
        private $foo = 'foo';
        public function __get($var) { return $this->$var; }
        public function __isset($var) { return isset($this->$var); }
    }
    
    $inst = new MyClass;
    if(empty($inst->foo))
    {
        print "empty";
    }
    else
    {
        print "full";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just discovered, quite by accident, that this seems to work: Public Interface Ix
To my amazement I just discovered that the C99 stdint.h is missing from MS
I've just discovered that Oracle lets you do the following: SELECT foo.a, (SELECT c
I have just discovered that if generating assemblies via Reflection.Emit, the .NET framework keeps
I only just recently discovered that Visual C++ 2008 (and perhaps earlier versions as
I have just discovered the nifty unhandled exception handler for cocoa-touch. Now that I
I've inherited a web app that I've just discovered stores over 300,000 usernames/passwords in
I'm sorry about the title I'm just not sure how to describe this one.
Rails gurus: I've just discovered named_scope thanks to another SO user. :) I'd like
I'm just getting dirty in WinForms, and I've discovered, through a lovely tutorial, the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.