param without ";" throws an error
Description
Activity
Arowolo Abiodun 2 August 2017 at 19:05
I just checked through the documentation, and discovered this
cfparam(name="foo", default="bar") // it works without semi-colon
Arowolo Abiodun 2 August 2017 at 18:58
What if I don't want to us the full attributes of cfparam (name, default and type)
I just want to do something like
param foo = 'bar'
If i can do
var foo = 'bar'
My argument is not for
param name='foo' default='bar' type='string'
Also, the code looks cleaner in my view
param name='foo' default='bar' type='string';
param name='bool_foo' default='true' type='boolean';
//=== alternative cfscript version could look like this
param foo = 'bar'
param bool_foo = true
param int_foo = 34
// === the above code works with semi colon
Brad Wood 29 July 2017 at 19:35
Sorry @Arowolo Abiodun, I've read your last reply several times but I have no idea what you're trying to say/ask :/ The issue is that the semi colon is required to remove the ambiguity that's present without it. When you write tags in a .cfm file, the parser knows where the tag starts and stops due to the < and > that wrap the tag so there is no ambiguity.
<cfparam name='foo'
default='bar'
type='string'>
Also consider this example, which has no whitespace at all.
<cfparam name='foo' default='bar'><cfset type='string'>
Again, no ambiguity. Now look at those two examples in script without semicolons.
param name='foo'
default='bar'
type='string'
and
param name='foo' default='bar' type='string'
These doesn't translate to script because there are no < > characters so the parser doesn't know when the tag has ended. The only way for the parser to reliably know where the tag stops is for there to always be a semicolon at the end of tag. It really makes no difference whether your tag is all on one line, multiple lines, or uses non-standard attributes, if the parser can't find the semicolon, it must throw an exception because it doesn't know where you wanted the tag to stop. Otherwise the first example could be seen as two separate statements and the second example could be seen as a single statement. The parser just doesn't know unless we always require a semi colon to end the tags.
Note, other languages that don't require a semi colon have different whitespace rules than CFML. These languages either don't allow whitespace at all or requires the whitespace to be escaped.
Arowolo Abiodun 29 July 2017 at 19:16
I get it, but your syntax is different from mine, its not having any attribute of cfparam/param
semi colon could be enforced if it has attribute
Brad Wood 29 July 2017 at 18:42
@Arowolo Abiodun This is an expected and necessary behavior. cfparam is a tag, and all tags require a semicolon after them. This is because CFML allows whitespace inside a tag so without the semicolon, it would be impossible for the parser to know where the tag ended! Take this example:
param name='foo'
default='bar' // Does the tag end here??
type='string' // Or here??
Without the semi colon, the parser can't know if "type='string'" is an attribute to the cfparam tag, or if it's a separate, unrelated variable creation of "variables.type".
Details
Assignee
UnassignedUnassignedReporter
Arowolo AbiodunArowolo AbiodunNew 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
Priority
Trivial
Details
Details
Assignee
Reporter
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
Hi,
param a = "b" // this throws an error param a = "b"; // this works
Can you help fix this so that param does not require ";"
Thank you