What's the best way in ACF2021 to detect if an arr...
# cfml-general
d
What's the best way in ACF2021 to detect if an array element has been set? For instance:
Copy code
a = [];
a[2] = "asdf";
b
I usually just use
isNull()
for that
Well, on Lucee anyway. Adobe CF seems to crap its pants-- at least on trycf.com
Copy code
a = [];
a[2] = "asdf";
writeDump( isNull( a[1] ) )
Seems a little broken in Adobe
Right, because ACF is apparenly dumb
If you're lucjy, you're using LUcee and won't have to deal with that nonsense 🙂
m
<cfscript> a = []; a[2] = "asdf"; if(NOT ArrayIsDefined(a, 1)){ writeDump(a); } </cfscript>
b
@Mark Takata (Adobe) This is a bug though, no? Lucee gets it right
m
That function name is poorly named 😛
b
UInintialied array elements are null, and therefore should not only NOT error, but return
true
from
isNull()
just like Lucee does
m
I mean, yes...ish? I agree that SHOULD be the case. They are being instantiated as undefined, which feels wrong (should be null). No idea why the heck its doing it that way
d
Thanks @Mark Takata (Adobe), but phht! You sure are right about that function name! Bleh.
m
haha yeah sorry Dave, that's one of those REALLY badly named functions that makes me want to tear my hair out
🙃 1
d
They're probably not instantiated at all.
b
I also don't understand why there is a need for a function called
arrayIsDefined()
when CFML already has a function called
isDefined()
whcih is supposed ot be able to accept any expression, array or not.
m
well, if you dump it, there's a position held in the array at the 1.
d
But referencing it as a text string is crappy anyway.
m
So, yes, if you tested isDefined() or even boolean true against it, it SHOULD return false
b
The code
Copy code
writeDump( isDefined( "a[1]" ) )
throws this error
Copy code
Parameter 1 of function IsDefined, which is now a[1], must be a syntactically valid variable name. on line 4
Which seems like yet another bug.
d
To put it differently, cfdump knows how to detect this.
b
Why did we add another version of isDefined when the original version should have just been fixed
m
For more fun, why is there a function called "ArrayIsEmpty"?
b
Again, Lucee's
isDefined()
works perfectlyk here
It is FAR too early and I am far too close to vacation to be up to my ears with this stuff today lol
🤣 1
b
Lucee has an
isEmpty()
function that simply works on any input type 🙂 https://cfdocs.org/isempty
You can pass Strings, Arrays, Structs and queries
m
Why can't it be like JavaScript, where you just can't ever figure out what is boolean true and false unless the moon is in the right phase and you just sacrificed a bucket of KFC? 😄
(kidding, obviously, JS makes me want to drink paint)
b
Copy code
NaN
m
I prefer naan 😄
b
declicious
m
(can you tell it is almost lunch here lol?)
b
My favorite Persian restaurant which made the best Naan in kansas city closed during Covid 😢
m
oh man, what a bummer 😞
Honestly Dave, I actually don't know. I have not been here long enough to have seen a "new" function name added. The new language features being developed for Fortuna are primarily GraphQL and we're just using the same nomenclature as what is in the docs for that. But I would also hope we'd do some research and checking on the names. I should also add, I have no idea how old that function name is. Like, I'm not sure when it was added. For all I know, it might be decades old.
z
It's a mess trying to avoid conflicts with existing code
t
According to the docs, ArrayIsDefined was added in CF8... So it's not quite decades old, but it's getting there.
But I think that means that it wasn't even Adobe that added it --- wasn't the first Adobe release CF9?
m
No, 8.
But honestly it was probably already spec'd by then