Evaluate()'ing a Function with "Nothing" Returned

So, I'm plugging away at some cool image effect stuff, and I decided that it would be nice to wrap all my image functionality into an object, and that it would be cool to try CF8's new onMissingMethod function to implement the built in function set as methods of this new object. The overall effect would be really nifty and fun to use, but I hit a big old snag; the Evaluate() function fails with "nothing" returned.

I looked up some help on how to pull off this dynamic evaluation and found this article from Kinky Solutions that includes a method for dynamically calling functions based on the missing method call, but the Evaluate() function throws an error if the evaluated function returns "nothing". What functions return "nothing"? Well the CF8 Image functions return "nothing" according to the documentation, and apparently this is totally different then having no return value or void return.

Pop this into the old CF server and you get no errors.

<cffunction name="getVoid" returntype="void">
    <cfreturn />
</cffunction>
<cfset Evaluate("getVoid()") />

Or this, its ok too.

<cffunction name="getVoid" returntype="void">
</cffunction>
<cfset Evaluate("getVoid()") />

Try this though, and everything goes wonky.

<cfset myImage = ImageRead("path\image.jpg") />
<cfset Evaluate("ImageSetDrawingColor(myImage, ""blue"")") />

But, switch it around to this, and things go ok:

<cfset myImage = ImageRead("path\image.jpg") />
<cfset Evaluate("ImageInfo(myImage)") />

Neat, huh?

Blarg.

 

Comments

Jon Hartmann, July 2011

I'm Jon Hartmann and I'm a Javascript fanatic, UX/UI evangelist and former ColdFusion master. I blog about mysterious error messages, user interface design questions, and all things baffling and irksome about programming for the web.

Learn more about me.

Post a job. Find one. authenticjobs.com

Interested in becoming a sponsor? Contact me.