# Not empty is not working with object in php 8.1

**URL:** <https://discourse.laminas.dev/t/not-empty-is-not-working-with-object-in-php-8-1/3209>\
**Category:** Uncategorized\
**Created:** [February 16, 2023, 11:23am UTC](https://discourse.laminas.dev/t/not-empty-is-not-working-with-object-in-php-8-1/3209 "2023-02-16T11:23:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Soft\_Solution](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/soft_solution/32/1425_2.png) [@Soft\_Solution](https://discourse.laminas.dev/u/Soft_Solution)\
**Post date:** [February 16, 2023, 11:23am UTC](https://discourse.laminas.dev/t/not-empty-is-not-working-with-object-in-php-8-1/3209/1 "2023-02-16T11:23:44Z")

</div>

Not empty is not working with object  
my object have value but code is not consider  
if(!empty($data-\>title)){  
echo “Yes”;  
}else{  
echo “No”;  
}

result is “No” why?  
suggest me what library is need to be install.

---

<div class="post-metadata">

**Author:** ![ezkimo](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/ezkimo/32/781_2.png) [@ezkimo](https://discourse.laminas.dev/u/ezkimo)\
**Post date:** [February 17, 2023, 12:44pm UTC](https://discourse.laminas.dev/t/not-empty-is-not-working-with-object-in-php-8-1/3209/2 "2023-02-17T12:44:15Z")

</div>

Hey @Soft_Solution,

it 's a bit difficult to answer since we know nothing about `$data`. Obviously `$data` should be an object in your code. Can you dump the content of `$data` so that we can see what type it is and which properties it got?

Just use the following code or copy the output from XDebug if your IDE supports it.

```auto
echo "<pre>";
var_dump($data);
echo "</pre>";

```

---

<div class="post-metadata">

**Author:** ![Soft\_Solution](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/soft_solution/32/1425_2.png) [@Soft\_Solution](https://discourse.laminas.dev/u/Soft_Solution)\
**Post date:** [February 17, 2023, 12:46pm UTC](https://discourse.laminas.dev/t/not-empty-is-not-working-with-object-in-php-8-1/3209/3 "2023-02-17T12:46:05Z")

</div>

I’m already do this but this is not working.

---

<div class="post-metadata">

**Author:** ![ezkimo](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/ezkimo/32/781_2.png) [@ezkimo](https://discourse.laminas.dev/u/ezkimo)\
**Post date:** [February 17, 2023, 12:47pm UTC](https://discourse.laminas.dev/t/not-empty-is-not-working-with-object-in-php-8-1/3209/4 "2023-02-17T12:47:39Z")

</div>

> This is not working

This is not a meaningful description of what is happening or what exactly is not working. What exactly is not working?

---

<div class="post-metadata">

**Author:** ![ezkimo](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/ezkimo/32/781_2.png) [@ezkimo](https://discourse.laminas.dev/u/ezkimo)\
**Post date:** [February 17, 2023, 1:01pm UTC](https://discourse.laminas.dev/t/not-empty-is-not-working-with-object-in-php-8-1/3209/5 "2023-02-17T13:01:12Z")

</div>

Here are a few examples how empty() works out with different values.

```auto
$data = stdClass;
$data->title = 'bla';

// is true because the title property is not empty
assert(empty($data->title) === false);

$data->title = null;

// true since the title property is null
assert(empty($data->title) === true);

$data->title = '';

// true since the title property is an empty string
assert(empty($data->title) === true);

$data->title = false;

// true because the title property is false
assert(empty($data->title) === true)

```

Please answer the following questions:

- How is your code looking?
- What type of is your `$data` object?

---

<div class="post-metadata">

**Author:** ![Soft\_Solution](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/soft_solution/32/1425_2.png) [@Soft\_Solution](https://discourse.laminas.dev/u/Soft_Solution)\
**Post date:** [February 23, 2023, 4:09am UTC](https://discourse.laminas.dev/t/not-empty-is-not-working-with-object-in-php-8-1/3209/6 "2023-02-23T04:09:42Z")

</div>

Thanks this is working
