Andy Jarrett // Code. Develop. Manage.

A comment on using CFParam inside a CFFunction

This is a response/comment to Steve Goods post named: Using CFParam Inside a CFFunction. Its turned into a blog post because, well I suppose I am looking for a wider feedback on my thoughts.

When it comes to using <cfparam> in a <cffunction> I would never of even contemplated it up to a few weeks ago, mainly because of the framework I was using gave me other ways of checking of variables existence.But I've moved over to Framework One (FW/1) which uses the tag in its controllers for some of the demos and I've now adopted this in to my recent code.

This then got me thinking that I cannot find a solid case reason as to write

if ( NOT StructKeyExists(myVar, "somekey") ){myVar.someKey = "0";}else if ( NOT isNumeric( myVar.somekey ) ){throw();}

when cfparam does that all in one go with basic type checking aswell.

You could wrap the if() logic in a function to be used but then aren't you just adding an extra layer to your code to do something CF already handles?


I’m here, learning and working away. If you liked this content and want to keep me going, consider buying me a coffee.
Your support keeps this site running and the coffee brewing! ☕️