This is basically the same behaviour as the standard PHP & TWIG coalescing ??-operator but with an additional not-empty-string-check.

Here an analyzed variable is declared as "not-empty", if ...

  • string:    Trimmed (!), string-length is >0.
  • integer:   Value is != 0
  • float:     Value is != 0.0
  • array:     Element-Count >0
  • object:    Member-Count >0
  • bool:      Value is TRUE

This function shall help if the normal ??-coalescing is insufficient, especially when dealing with empty strings or empty arrays.

Syntax

hublify.coalesceEmpty(...$vars): mixed|null