★ wanayoo — archive 1999 http://www.php.net/manual/function.define.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to Misc.
Quick Reference
Misc.
* connection_aborted
* connection_status
* connection_timeout
* define
* defined
* die
* eval
* exit
* func_get_arg
* func_get_args
* func_num_args
* function_exists
* get_browser
* ignore_user_abort
* iptcparse
* leak
* pack
* register_shutdown_function
* serialize
* sleep
* uniqid
* unpack
* unserialize
* usleep
Manual: define
View the source code for this pageSearch the site



Previous page
 connection_timeout
defined 
Next page


define

define -- Defines a named constant.

Description

int define(string name, mixed value, int [case_insensitive] );

Defines a named constant, which is similar to a variable except:

  • Constants do not have a dollar sign '$' before them;

  • Constants may be accessed anywhere without regard to variable scoping rules;

  • Constants may not be redefined or undefined once they have been set; and

  • Constants may only evaluate to scalar values.

The name of the constant is given by name; the value is given by value.

The optional third parameter case_insensitive is also available. If the value 1 is given, then the constant will be defined case-insensitive. The default behaviour is case-sensitive; i.e. CONSTANT and Constant represent different values.

Example 1. Defining Constants

  1 
  2 <?php
  3 define ("CONSTANT", "Hello world.");
  4 echo CONSTANT; // outputs "Hello world."
  5 ?>
  6       

define() returns TRUE on success and FALSE if an error occurs.

See also defined() and the section on Constants.


User Contributed Notes: define


terry@terrym.com
12-Apr-2000 06:05
This page say's: <p> <blockquote> Constants may be accessed anywhere without regard to variable scoping rules; </blockquote> <p> But this is not exactly true, if it is to be seen by functions in an include file, then it must be defined before any include (or requier? not tested) statements. <p> Terry


terry@terrym.com
12-Apr-2000 06:22
To be more exact, it must be BEFORE any place it is used. 
It can be put in an include file, or the main file.
But must be defined before it is used.
So probably best to put them at the top of the main file
or at the top of the first include file,
if that include is the first thing in the main file.

Terry


froyer@free.fr
12-May-2000 11:53
I would like to known what is the maximum characters number that could be allowed for a constant ( 32 ??) Thanks


 About Notes


Previous page
 connection_timeout
defined 
Next page



Site Statistics


Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.