<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://debianws.lexgopc.com/wiki143/index.php?action=history&amp;feed=atom&amp;title=Undefined_variable</id>
	<title>Undefined variable - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://debianws.lexgopc.com/wiki143/index.php?action=history&amp;feed=atom&amp;title=Undefined_variable"/>
	<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki143/index.php?title=Undefined_variable&amp;action=history"/>
	<updated>2026-10-25T23:41:58Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>http://debianws.lexgopc.com/wiki143/index.php?title=Undefined_variable&amp;diff=1904966&amp;oldid=prev</id>
		<title>imported&gt;Duckmather: /* Python 2.4 */ update to add Python 3 behavior</title>
		<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki143/index.php?title=Undefined_variable&amp;diff=1904966&amp;oldid=prev"/>
		<updated>2024-02-16T20:31:52Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Python 2.4: &lt;/span&gt; update to add Python 3 behavior&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;An &amp;#039;&amp;#039;&amp;#039;undefined variable&amp;#039;&amp;#039;&amp;#039; in the [[source code]] of a [[computer program]] is a [[variable (programming)|variable]] that is accessed in the code but has not been [[Declaration (computer science)|declared]] by that code.&amp;lt;ref&amp;gt;&amp;quot;undefined variable.&amp;quot; YourDictionary, n.d. Web. 24 July 2013. &amp;lt;http://computer.yourdictionary.com/undefined-variable&amp;gt;.&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In some [[programming languages]], an implicit declaration is provided the first time such a variable is encountered at [[compile time]].  In other languages such a usage is considered to be sufficiently serious that a diagnostic being issued and the compilation fails.&lt;br /&gt;
&lt;br /&gt;
Some language definitions initially used the implicit declaration behavior and as they matured provided an option to disable it (e.g. [[Perl]]&amp;#039;s &amp;quot;&amp;lt;code&amp;gt;use warnings&amp;lt;/code&amp;gt;&amp;quot; or [[Visual Basic]]&amp;#039;s &amp;quot;&amp;lt;code&amp;gt;Option Explicit&amp;lt;/code&amp;gt;&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
The following provides some examples of how various programming language implementations respond to undefined variables.  Each code snippet is followed by an error message (if any).&lt;br /&gt;
&lt;br /&gt;
===[[CLISP]] ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
(setf y x)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
 *** - EVAL: variable X has no value&lt;br /&gt;
&lt;br /&gt;
===[[C (programming language)|C]]===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int main() {&lt;br /&gt;
  int y = x;&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
 foo.c: In function `main&amp;#039;:&lt;br /&gt;
 foo.c:2: error: `x&amp;#039; undeclared (first use in this function)&lt;br /&gt;
 foo.c:2: error: (Each undeclared identifier is reported only once&lt;br /&gt;
 foo.c:2: error: for each function it appears in.)&lt;br /&gt;
&lt;br /&gt;
===[[JavaScript]] ===&lt;br /&gt;
&lt;br /&gt;
A ReferenceError only happens if the same piece of executed code has a {{code|let|lang=js}} or a {{code|const|lang=js}} (but not {{code|var|lang=js}}) declaration later on, or if the code is executed in strict mode. In all other cases, the variable will have the special value {{code|undefined|lang=js}}.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
&amp;quot;use strict&amp;quot;;&lt;br /&gt;
let y = x;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
let y = x;&lt;br /&gt;
let x; // causes error on line 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
  ReferenceError: x is not defined&lt;br /&gt;
  Source File: file:///c:/temp/foo.js&lt;br /&gt;
&lt;br /&gt;
===[[Lua (programming language)|Lua]]===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
y = x&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
(no error, continuing)&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(y)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
 nil&lt;br /&gt;
&lt;br /&gt;
===[[Standard ML|ML]] (Standard ML of New Jersey) ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sml&amp;quot;&amp;gt;&lt;br /&gt;
val y = x;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
 stdIn:1.9 Error: unbound variable or constructor: x&lt;br /&gt;
&lt;br /&gt;
===[[MUMPS]]===&lt;br /&gt;
&lt;br /&gt;
 Set Y=X&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;UNDEF&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===[[OCaml]] ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ocaml&amp;quot;&amp;gt;&lt;br /&gt;
let y = x;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
 Unbound value x&lt;br /&gt;
&lt;br /&gt;
===[[Perl]]===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
my $y = ($x // 0) + 1; # defined-or operator&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
 (no error)&lt;br /&gt;
&lt;br /&gt;
===[[PHP]] 5===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$y = $x;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
 (no error)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$y=&amp;quot;&amp;quot;;&lt;br /&gt;
$x=&amp;quot;&amp;quot;;&lt;br /&gt;
error_reporting(E_ALL);&lt;br /&gt;
$y = $x;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
 PHP Notice:  Undefined variable: x in foo.php on line 3&lt;br /&gt;
&lt;br /&gt;
===[[Python (programming language)|Python]]===&lt;br /&gt;
&lt;br /&gt;
==== Python 3 ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python3&amp;quot;&amp;gt;&lt;br /&gt;
x = y&lt;br /&gt;
Traceback (most recent call last):&lt;br /&gt;
  File &amp;quot;&amp;lt;pyshell#0&amp;gt;&amp;quot;, line 1, in &amp;lt;module&amp;gt;&lt;br /&gt;
    x = y&lt;br /&gt;
NameError: name &amp;#039;y&amp;#039; is not defined&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Python 2.4 ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pycon&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; x = y&lt;br /&gt;
Traceback (most recent call last):&lt;br /&gt;
  File &amp;quot;&amp;lt;stdin&amp;gt;&amp;quot;, line 1, in &amp;lt;module&amp;gt;&lt;br /&gt;
NameError: name &amp;#039;y&amp;#039; is not defined&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===[[REXX]]===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;rexx&amp;quot;&amp;gt;&lt;br /&gt;
signal on novalue&lt;br /&gt;
y = x&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
 +++ Error 30 in line 2: Label not found&lt;br /&gt;
&lt;br /&gt;
===[[Ruby (programming language)|Ruby]] ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;irb&amp;quot;&amp;gt;&lt;br /&gt;
irb(main):001:0&amp;gt; y = x&lt;br /&gt;
NameError: undefined local variable or method `x&amp;#039; for main:Object&lt;br /&gt;
	from (irb):1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===[[Tcl]] ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;tcl&amp;quot;&amp;gt;&lt;br /&gt;
% set y $x&lt;br /&gt;
can&amp;#039;t read &amp;quot;x&amp;quot;: no such variable&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===[[VBScript]] ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vbscript&amp;quot;&amp;gt;&lt;br /&gt;
Dim y&lt;br /&gt;
y = x&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
 (no error)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vbscript&amp;quot;&amp;gt;&lt;br /&gt;
Option Explicit&lt;br /&gt;
&lt;br /&gt;
Dim y&lt;br /&gt;
y = x&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
 (3, 1) Microsoft VBScript runtime error: Variable is undefined: &amp;#039;x&amp;#039;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{Reflist}}&lt;br /&gt;
&lt;br /&gt;
{{DEFAULTSORT:Undefined Variable}}&lt;br /&gt;
[[Category:Variable (computer science)]]&lt;br /&gt;
[[Category:Software bugs]]&lt;/div&gt;</summary>
		<author><name>imported&gt;Duckmather</name></author>
	</entry>
</feed>