sequence icon indicating copy to clipboard operation
sequence copied to clipboard

replace broad empty() with more explicit filters

Open shampine opened this issue 9 months ago • 0 comments

if (in_array($snakeCasePropertyName, $this->excludeWhenEmpty) && empty($propertyValue)) continue;

empty() treats 0, "0", false, and [] as empty. So if someone wants to return "count" => 0 or "enabled" => false, it could disappear depending on config. That’s not a bug, but it’s a “why did my API lie to me?” moment.

A nicer library-level option is: replace broad empty() with more explicit filters (null only, empty string only, empty array only), or clearly document “excludeWhenEmpty uses PHP empty semantics.”

shampine avatar Feb 13 '26 05:02 shampine