isEmpty() vs Empty() in Lucee 6

I’m noticing a difference between Lucee 5 and Lucee 6.

Previously, when I used the function isEmpty() it behaved the same way as the now deprecated Empty() function - it checked both whether the variable existed and if it was empty.

Now there is a difference. Now it throws an error if the variable is not defined.

Which means writing something annoying like not isDefined("var") or isEmpty(var) to make the check.

Or I can just change it to the deprecated “Empty(var)” which is considerably more concise.

Is this a bug? Or is there a config setting I can tweak to get the old behaviour back for isEmpty? It definitely worked in Lucee 5.

Stack is Commandbox Lucee-Light@6.1.0+00813

In my opinion…from language perspective neither empty() nor isEmpty() and also according to the docs, nothing relates to saying it does include some sort of isDefined() checking functionality. If so, I’d consider it to be a bug, because I’d always expect the variable to exist. Also, isDefined() has been deprecated for a while, so I’d prefer using varibales.keyExists("foo") && variables.foo.isEmpty(). Even better would be making use of cfparam() which have been introduced to address exactly that situation with more modern best practices.

This is from the empty() docs:

This function returns true if a value exists and is not “empty”.

Edit: Hmm, though I guess that doesn’t say it returns empty() if it doesn’t exist. I misread that.

And yet, that is the behaviour that it had.

I guess I’ll just adjust my code to match this behaviour.

1 Like