<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML ><HEAD ><TITLE >Creating Constants</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="Manual PHP" HREF="index.html"><LINK REL="UP" TITLE="Creating Variables" HREF="zend.variables.html"><LINK REL="PREVIOUS" TITLE="Macros for Automatic Global Variable Creation" HREF="zend.variables.global.html"><LINK REL="NEXT" TITLE="Duplicating Variable Contents: The Copy Constructor" HREF="zend.copy-constructor.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-2"></HEAD ><BODY CLASS="section" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >Manual PHP</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="zend.variables.global.html" ACCESSKEY="P" >Înapoi</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" >Cap. 35. Creating Variables</TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="zend.copy-constructor.html" ACCESSKEY="N" >Înainte</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="zend.variables.constant" >Creating Constants</A ></H1 ><P > Zend supports the creation of true constants (as opposed to regular variables). Constants are accessed without the typical dollar sign (<VAR CLASS="literal" >$</VAR >) prefix and are available in all scopes. Examples include <VAR CLASS="literal" >TRUE</VAR > and <VAR CLASS="literal" >FALSE</VAR >, to name just two. </P ><P > To create your own constants, you can use the macros in <A HREF="zend.variables.constant.html#tab.create-const" >Tabel 35-6</A >. All the macros create a constant with the specified name and value. </P ><P > You can also specify flags for each constant: <P ></P ><UL ><LI ><P > <VAR CLASS="literal" >CONST_CS</VAR > - This constant's name is to be treated as case sensitive. </P ></LI ><LI ><P > <VAR CLASS="literal" >CONST_PERSISTENT</VAR > - This constant is persistent and won't be "forgotten" when the current process carrying this constant shuts down. </P ></LI ></UL > To use the flags, combine them using a inary OR: <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >// register a new constant of type "long" REGISTER_LONG_CONSTANT("NEW_MEANINGFUL_CONSTANT", 324, CONST_CS | CONST_PERSISTENT);</PRE ></TD ></TR ></TABLE > There are two types of macros - <VAR CLASS="literal" >REGISTER_*_CONSTANT</VAR > and<VAR CLASS="literal" >REGISTER_MAIN_*_CONSTANT</VAR >. The first type creates constants bound to the current module. These constants are dumped from the symbol table as soon as the module that registered the constant is unloaded from memory. The second type creates constants that remain in the symbol table independently of the module. </P ><DIV CLASS="table" ><A NAME="tab.create-const" ></A ><P ><B >Tabel 35-6. Macros for Creating Constants</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><COL WIDTH="1.53*" TITLE="col1"><COL WIDTH="1*" TITLE="col2"><TBODY ><TR ><TD >Macro</TD ><TD >Description</TD ></TR ><TR ><TD > <VAR CLASS="literal" >REGISTER_LONG_CONSTANT(name, value, flags)</VAR > <VAR CLASS="literal" >REGISTER_MAIN_LONG_CONSTANT(name, value, flags)</VAR > </TD ><TD >Registers a new constant of type long.</TD ></TR ><TR ><TD > <VAR CLASS="literal" >REGISTER_DOUBLE_CONSTANT(name, value, flags)</VAR > <VAR CLASS="literal" >REGISTER_MAIN_DOUBLE_CONSTANT(name, value, flags)</VAR > </TD ><TD >Registers a new constant of type double.</TD ></TR ><TR ><TD > <VAR CLASS="literal" >REGISTER_STRING_CONSTANT(name, value, flags)</VAR > <VAR CLASS="literal" >REGISTER_MAIN_STRING_CONSTANT(name, value, flags)</VAR > </TD ><TD > Registers a new constant of type string. The specified string must reside in Zend's internal memory.</TD ></TR ><TR ><TD > <VAR CLASS="literal" >REGISTER_STRINGL_CONSTANT(name, value, length, flags)</VAR > <VAR CLASS="literal" >REGISTER_MAIN_STRINGL_CONSTANT(name, value, length, flags)</VAR > </TD ><TD >Registers a new constant of type string. The string length is explicitly set to <VAR CLASS="envar" >length</VAR >. The specified string must reside in Zend's internal memory.</TD ></TR ></TBODY ></TABLE ></DIV ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="zend.variables.global.html" ACCESSKEY="P" >Înapoi</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Acasã</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="zend.copy-constructor.html" ACCESSKEY="N" >Înainte</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Macros for Automatic Global Variable Creation</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="zend.variables.html" ACCESSKEY="U" >Sus</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Duplicating Variable Contents: The Copy Constructor</TD ></TR ></TABLE ></DIV ></BODY ></HTML >