IsValid( "string", object ) returns true for image

Description

IsValid( "string", object ) returns true when passed an image object.

Sample

newImage = ImageNew( "", 1, 1 ); Dump( IsValid( "string", newImage ) );

Expected value

false

Actual value

true

Works as expected under Lucee 4.5

Environment

Windows 10, Java 1.8, Tomcat 8.5

Activity

Michael Offner 
8 May 2017 at 18:14

sure we can discuss options to change this, maybe at a more strict function.

Michael Offner 
8 May 2017 at 18:12

Julian Halliwell 
8 May 2017 at 16:27

Understood, and agreed the workaround is easy. But it's still important to note then that is a breaking change between versions 4.5 and 5

Michael Offner 
8 May 2017 at 16:24

workaround: use the function

isSimpleValue

instead.

Michael Offner 
8 May 2017 at 16:22

after looking into it i have to report, this is not a bug, this works that way for compatibility reason to ACF.
https://trycf.com/gist/f2cfdcd18ab8bc9118c8a7737cff3ef9/acf2016?theme=monokai

BUT HOW CAN THIS MAKE SENSE!?
Have in mind that lucce is not a typed language, if you check a type you do not check if a object is of that type, you check if that object can be cast to that type.
so for example the following is absolutely fine.

function test(boolean b) { } test('true'); test(37);

you don't get an error with this code because Lucee can convert the string and number passed to the function to a boolean. When ACF did add support for this types, they had to add this flexibility to be more backward compatible.

With "isValid" we have the same situation, an image object can be converted to a string and because of that

isValid('string',img)

is true.
https://trycf.com/gist/11c5429eb6bbaa901d4269ea100c20ef/lucee5?theme=monokai

I completely understand that this is confusing, I myself had a different interpretation first. this means that we have to point out this in the doc clearly.

Won't Do

Details

Assignee

Reporter

Priority

New Issue warning screen

Before you create a new Issue, please post to the mailing list first https://dev.lucee.org

Once the issue has been verified, one of the Lucee team will ask you to file an issue

Affects versions

Created 13 March 2017 at 10:14
Updated 14 May 2025 at 11:54
Resolved 8 May 2017 at 18:13