This page shows the source for this entry, with WebCore formatting language tags and attributes highlighted.
Title
Beware constants in ASP (scripting bug)
Description
There is a bug in scope resolution in IIS 5.0. When resolving a variable within a member function, precedence is given to a global constant instead of to a member variable of the same name. The problem does not occur with global variables. Paste the following code into a page:
<box title="Sample Code">
<code>
<%
<b>const</b> name = 1
<b>class</b> A
<b>public</b> name
<b>public function</b> get_name
get_name = name
<b>end function</b>
<b>end class</b>
<b>dim</b> a1
<b>set</b> a1 = <b>new</b> A
a1.name = "test"
%>
<%=name%><br>
<%=a1.name%><br>
<%=a1.get_name%><br></code>
</box>
All it does is declare a constant, a class with one function, then outputs some data. The expected output is:
<pre>1
test
test</pre>
However, IIS emits:
<pre>1
test
1</pre>
If you replace:
<code><b>const</b> name = 1</code>
with:
<code><b>dim</b> name
name = 1</code>
it emits:
<pre>1
test
test</pre>
as expected.
If you replace:
<code><b>public function</b> get_name
get_name = name
<b>end function</b></code>
with (change is highlighted):
<code><b>public function</b> get_name
get_name = <hl>me</hl>.name
<b>end function</b></code>
it emits:
<pre>1
test
test</pre>
as expected.
<sarcasm>Here's looking forward to .NET.</sarcasm>