<HTML ><HEAD ><TITLE >Using old code with new versions of PHP</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="PHP Manual" HREF="index.html"><LINK REL="UP" TITLE="A simple tutorial" HREF="tutorial.html"><LINK REL="PREVIOUS" TITLE="Dealing with Forms" HREF="tutorial.forms.html"><LINK REL="NEXT" TITLE="What's next?" HREF="tutorial.whatsnext.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></HEAD ><BODY CLASS="sect1" 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" >PHP Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="tutorial.forms.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" >Chapter 2. A simple tutorial</TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="tutorial.whatsnext.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="tutorial.oldcode" ></A >Using old code with new versions of PHP</H1 ><P > Now that PHP has grown to be a popular scripting language, there are more resources out there that have listings of code you can reuse in your own scripts. For the most part the developers of the PHP language have tried to be backwards compatible, so a script written for an older version should run (ideally) without changes in a newer version of PHP, in practice some changes will usually be needed. </P ><P > Two of the most important recent changes that affect old code are: <P ></P ><UL ><LI ><P > The deprecation of the old <TT CLASS="varname" >$HTTP_*_VARS</TT > arrays (which need to be indicated as global when used inside a function or method). The following <A HREF="language.variables.predefined.html#language.variables.superglobals" >autoglobal arrays</A > were introduced in PHP <A HREF="http://www.php.net/release_4_1_0.php" TARGET="_top" >4.1.0</A >. They are: <TT CLASS="varname" >$_GET</TT >, <TT CLASS="varname" >$_POST</TT >, <TT CLASS="varname" >$_COOKIE</TT >, <TT CLASS="varname" >$_SERVER</TT >, <TT CLASS="varname" >$_ENV</TT >, <TT CLASS="varname" >$_REQUEST</TT >, and <TT CLASS="varname" >$_SESSION</TT >. The older <TT CLASS="varname" >$HTTP_*_VARS</TT > arrays, such as $HTTP_POST_VARS, still exist and have since PHP 3. </P ></LI ><LI ><P > External variables are no longer registered in the global scope by default. In other words, as of PHP <A HREF="http://www.php.net/release_4_2_0.php" TARGET="_top" >4.2.0</A > the PHP directive <A HREF="configuration.directives.html#ini.register-globals" >register_globals</A > is <SPAN CLASS="emphasis" ><I CLASS="emphasis" >off</I ></SPAN > by default in <TT CLASS="filename" >php.ini</TT >. The preferred method of accessing these values is via the autoglobal arrays mentioned above. Older scripts, books, and tutorials may rely on this directive being on. If on, for example, one could use <TT CLASS="varname" >$id</TT > from the URL <TT CLASS="literal" >http://www.example.com/foo.php?id=42</TT >. Whether on or off, <TT CLASS="varname" >$_GET['id']</TT > is available. </P ></LI ></UL > For more details on these changes, see the section on <A HREF="language.variables.predefined.html" >predefined variables</A > and links therein. </P ></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="tutorial.forms.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="tutorial.whatsnext.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Dealing with Forms</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="tutorial.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >What's next?</TD ></TR ></TABLE ></DIV ></BODY ></HTML >