Check out this inconsistency in Lucee where functi...
# lucee
b
Check out this inconsistency in Lucee where function argument defaults aren't applied when • the UDF was called via
argumentCollection
with not all args supplied • named arguments were used • full null support is enabled https://trycf.com/gist/b5724b0207694e00ed506327a066332d/lucee5?theme=monokai
šŸ™Œ 1
In the first dump,
arg2
is null, meaning the default value didn't kick in.
I assume this is a bug. At first I thoughut perhaps it was working as designed since
null
is more of a proper and "acknowledged" value when full null support is enabled, but when I saw named params and positional params behaved differently, I wasn't so sure.
g
oooh, scary
only UDF's ? or functions in CFC's as well ?
also, does this only appear to be an issue with null support enabled ?
b
Functions in a CFC are a UDF 😁
😜 1
a
but when I saw named params and positional params behaved differently
I think this nails it as a bug. I see where you were coming from initially, but something is off if the two ways of specifying the function arguments differ.
d
It looks like this is caused by the way difference in the way Lucee handles named arguments vs positional arguments. Here's a Gist which adds a dump to the arguments scope: https://trycf.com/gist/9e7095d32923a4c05e0b81b91556bcdd/lucee5?theme=monokai When you run that, you can see that when named arguments are passed, the function dumps: arg1=456 arg2=null But when positional arguments are used, you just get: arg1=256 There is no arg2. This seems like a bug to me. Even when named arguments are supplied, if an argument is undefined then it should stay undefined. It's one of the reasons why the concept of
null
and
undefined
in a scripting language like JS have always made sense to me (and I know that's contrary to what a lot of devs think). I see
null
as a way to say "I'm aware of this variable, but I have no idea what it's value should be" and
undefined
is saying "What? I've never heard of such a thing". In this case,
arg2
isn't
null
it's
undefined
. It was never defined in the arguments and has no default value.
a
(and I know that's contrary to what a lot of devs think). I see
null
as a way to say "I'm aware of this variable, but I have no idea what it's value should be" and
undefined
is saying "What? I've never heard of such a thing".
I don't know a single dev who doesn't think this. Except some muppets from the dark history of CFML, I mean.
Was it possible to create a situation in CFML where a variable assignment (/creation) could have a null value? Adding UDFs in CF5 mighta caused this. Although what about other-language integration in earlier versions where a cfx tag called something that "returned" null>
d
x = javaCast("null", "")
a
Yeah I think that only got added to CFML in CFMX6
d
and: function createNull(){ return; }
a
CF5
d
CF5 was written in C++. I don't think there was any concept of
null
from that time period.
That came around when the code was migrated to Java in MX (i.e. 6)
a
yeah this is my point. CFML didn't have any need to support a concept of an expression being null prior to CF5. Possibly. And they probably forgot to do anything about it in CF5 and CFMX6. And then... ballsed it up
And - less than popular opinion - Lucee's toggleable null support only made the situation worse.
(full disclosure: I think I was supportive of it initially. Until I tried to write cross-platform code or shared-code)
b
Thanks for the input, I'll enter a ticket
āœ… 2
d
I put my comment from above into the issue, just so it's preserved
šŸ‘ 3