faqts : Computers : Programming : Languages : PHP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

33 of 39 people (85%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

What is this mean: Warning: Use of undefined constant

Mar 15th, 2008 18:13
ha mo, Philip Olson, Leong Kah Ming,


This can mean many things, the simplest is:
  print UNDEFINED;
You may want to read up on constants to fully understand what they are:
  http://www.php.net/manual/en/language.constants.php
Anyway, odds are you got this error from not quoting an array index, 
something like:
  print $arr[key];
PHP first looks for a constant named key and if it does not find it, 
PHP will throw an error of level E_NOTICE that is described 
as "Undefined Constant".  After this PHP will look for an array index 
named 'key' and use it.  Here's another example:
  define('a', 'b');
  $arr = array('a' => 'apple', 'b' => 'banana');
  print $arr[a];   // banana
  print $arr['a']; // apple
See?  PHP used the constant named   a   when not quoted.  So keep this 
in mind.  
On a related note, undefined variables and constants are errors of 
level E_NOTICE and a default PHP install does not show these level of 
errors.
See also:
  http://www.php.net/error_reporting
  http://www.php.net/constants
  http://www.php.net/types.array
http://www.tantofa.com
http://www.fantofa.com
http://www.mantofa.com
http://www.tanpola.com
http://www.tampola.com
http://www.yamot.com
http://www.mozmar.com
http://www.templatestemp.com