Hi there,
Is this a bug?
form.allGood = myJunkScope?.myJunkStruct?.myjunkNestedStruct?.theKeyImAfter;
writeDump("#structKeyExists(form, "allGood")#");
// returns FALSE
but if I dump the form - the allGood variable is seen.
form.allGood = myJunkScope?.myJunkStruct?.myjunkNestedStruct?.theKeyImAfter;
writeDump("#structKeyExists(form, "allGood")#");
// returns FALSE
writeDump(var="#form#");
// allGood key DOES exist in dump of form - with a NULL value.
Shouldn’t the structKeyExists() call return true?
We’re using v5.3.10.120
(yes, we know it’s old!)
structkeyexists returns false for null values
I think this is a bug - at least in the sense that it behaves differently than I think it would be reasonably assumed that it should.
The function asks whether a key exists… not whether or not a key exists AND the value is not null.
I am happy to raise a ticket and also to create a PR for the docs, to note it’s current behaviour when the value is null.
Does anyone have any comments, before I do so?
mate, this is simply how cfml works, do some quick research if you don’t believe me
don’t raise a ticket.
it works differently when full null support is enabled
Hi Zac,
You beat me to it.
I worked out that - if you enable NULL support - then structKeyExists() behave entirely as I would expect.
Would you accept a DOCS PR - for the differentiation of it’s behaviour, depending on the NULL Support setting?
1 Like
absolutely, that would rock!
2 Likes
thanks, i tweaked a bit to refer to CFML rather than Lucee and cross referenced it to the null support docs
and I enabled / updated the isNull() tests
/**
* Copyright (c) 2016, Lucee Association Switzerland. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
component extends="org.lucee.cfml.test.LuceeTestCase" {
function run( testResults, testBox ) {
This file has been truncated. show original
1 Like