Quick Snippet to Verify All Object Properties are Not Empty

Nov 16, 2017 php
This post is more than 18 months old. Since technology changes too rapidly, this content may be out of date (but that's not always the case). Please remember to verify any technical or programming information with the current release.

If you check out array_filter without a callback, you’ll notice that it will basically check each array key to make sure it doesn’t equal false. If you have an object, you get call of the properties as an array using get_object_vars. This quick snippet will allow you to look at an object and verify each property is non-false (or non-empty).

if (array_filter(get_object_vars($object)) == get_object_vars($object)) {
  // each property is non-empty
}

Simple and sometimes useful.

Go to All Posts