How to create a default object from empty value in PHP?

Spread the love

Sometimes, we want to create a default object from empty value in PHP.

In this article, we’ll look at how to create a default object from empty value in PHP.

How to create a default object from empty value in PHP?

To create a default object from empty value in PHP, we can use the stdClass class.

For instance, we write

$res = new \stdClass();
$res->success = false;

to creatr the empty $res object with the stdClass class.

Then we set its success property to false.

Conclusion

To create a default object from empty value in PHP, we can use the stdClass class.

Leave a Reply

Your email address will not be published.