Woah woah woah. I want to be sure we are -very- clear here. Peter, you said,
With CF9 you don't need the var keyword anymore, and if you don't
need backwards compatible code it's (arguably) clearer to not use it
at all.
That is not true. You do need to var scope. What you don't need to do
is
Sorry, yeah, that was worded badly.
I should have prefixed that with If you *always* use the local scope, you
don't need var...
Annoyingly I can't go back and revise the message, and for some reason it got
posted twice too. :/
Thank you Ray and Peter for your answers/clarification on this question. It's
clear now and every helpful.
Jerry
~|
Order the Adobe Coldfusion Anthology now!
Hello,
We are discussing the proper way to initialize a query in a cffunction. Does
it make a significant difference to use QueryNew rather than (empty string)
as in the following:
cfcomponent
cffunction name=test access=public returntype=query output=false
.this?
cfset var
creates the myQuery variable as a string and not as a
query.
It does. But as soon as your run the cfquery the myQuery variable is
essentially becomes a query object.
Does it make a significant difference to
use QueryNew rather than (empty string) as in the
following:
For a function
It doesn't matter - CFML is not like Java (where you must pre-define variables
with strict types). In CFML, variables can change types at any time.
If you're just var scoping a cfquery variable, it doesn't matter what you use.
(I would guess using QueryNew might be ever so slightly slower -
Leigh, Peter,
Thanks for your comments. All makes sense to me. If I can ask one follow-up on
Peter's answer though. I've recently started to work on CF9 and was using my
cffunction techniques from the CF8 days. i.e.,
cfset var local = StructNew()
cfset local.myVar1 =
cfset local.myVar2 =
With CF9 you don't need the var keyword anymore, and if you don't need
backwards compatible code it's (arguably) clearer to not use it at all.
That means, do NOT use either of your examples, unless you _need_ a value in
myvar1/myvar2 at the start.
Perhaps a good way to explain it is to use
With CF9 you don't need the var keyword anymore, and if you don't need
backwards compatible code it's (arguably) clearer to not use it at all.
That means, do NOT use either of your examples, unless you _need_ a value in
myvar1/myvar2 at the start.
Perhaps a good way to explain it is to use
Peter, great examples, really helpful.
In a nutshell, if I get it, in CF9 you do not need to use:
cfset var local = StructNew() /
because you are going to define your vars as: local.myVar1 and local.myVar2
and the local structure is already defined by default.
You refer to your vars
10 matches
Mail list logo