ColdFusion

Results 1 - 10 of around 2 in coldfusion

Sometimes it's the little things

It's not often I'm stumped with an error in ColdFusion, but this one had me for a while.

I've been doing this ColdFusion thing for, as of today, a month short of 7 years. I'm not often suprised by CF but this had me thinking long and hard for embarrassing longer than I would like to admit.

Now, without looking too far down the page, what would you expect from the following:

<cfset VARIABLES.someVar = "">

<cfif someConditionThatMightBeTrue>

	<cfset VARIABLES.someVar = CreateObject("component", "path.to.my.cfc")>
</cfif>

<cfif VARIABLES.someVar EQ "">
	We haven't created the object yet.
<cfelse>
	We have an object!
</cfif>

Me? I was thinking it would work as I wanted. Check to see if VARIABLES.someVar was an empty string, if not, the object hadn't been created.

Why then did it take me so long to see that comparing a string to an object, once it had been created, with EQ was the reason things weren't working as I expected?

You'd think the following error would have speeded up the debugging process also!

Complex object types cannot be converted to simple values.

Anyway, the point is. Use IsSimpleValue() rather than EQ.

Comments

Very well done! Even thou you forced me to read it!

Willy - Monday 17 December 2007 at 19:56

Haha! My second favourite willy! :OD

Dirty Bungle - Thursday 27 December 2007 at 00:28

Or use isObject(). :) The one that actually got me hacked off is this... if you try isXmlNode(StructNew()) instead of simply returning false, like it should, it throws an error to let you know that the structure isn't XML... which presumably is what you wanted to know in the first place. :P But rather than just returning yes or no, it gets its shorts in a knot because you asked the question.

Question: Is the Eiffel tower a dog?

Answer: I can't answer that because the Eiffel tower isn't an animal!

uhhh... you just did answer it.

ike - Tuesday 17 June 2008 at 16:23

Ah, good point on the IsObject() front!

Adrian Lynch - Wednesday 25 June 2008 at 08:18

Add comment

Name

Comment

Website