<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Using old code with new versions of PHP</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="tutorial.forms.html">Dealing with Forms</a></div> <div class="next" style="text-align: right; float: right;"><a href="tutorial.whatsnext.html">What's next?</a></div> <div class="up"><a href="tutorial.html">A simple tutorial</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="tutorial.oldcode" class="section"> <div class="info"><h1 class="title">Using old code with new versions of PHP</h1></div> <p class="para"> Now that PHP has grown to be a popular scripting language, there are a lot of public repositories and libraries containing code you can reuse. The PHP developers have largely tried to preserve backwards compatibility, so a script written for an older version will run (ideally) without changes in a newer version of PHP. In practice, some changes will usually be needed. </p> <p class="para"> Two of the most important recent changes that affect old code are: <ul class="itemizedlist"> <li class="listitem"> <span class="simpara"> The deprecation of the old <var class="varname"><var class="varname">$HTTP_*_VARS</var></var> arrays (which need to be indicated as global when used inside a function or method). The following <a href="language.variables.superglobals.html" class="link">superglobal arrays</a> were introduced in PHP <a href="http://www.php.net/releases/4_1_0.php" class="link external">» 4.1.0</a>. They are: <var class="varname"><var class="varname"><a href="reserved.variables.get.html" class="classname">$_GET</a></var></var>, <var class="varname"><var class="varname"><a href="reserved.variables.post.html" class="classname">$_POST</a></var></var>, <var class="varname"><var class="varname"><a href="reserved.variables.cookies.html" class="classname">$_COOKIE</a></var></var>, <var class="varname"><var class="varname"><a href="reserved.variables.server.html" class="classname">$_SERVER</a></var></var>, <var class="varname"><var class="varname"><a href="reserved.variables.files.html" class="classname">$_FILES</a></var></var>, <var class="varname"><var class="varname"><a href="reserved.variables.environment.html" class="classname">$_ENV</a></var></var>, <var class="varname"><var class="varname"><a href="reserved.variables.request.html" class="classname">$_REQUEST</a></var></var>, and <var class="varname"><var class="varname"><a href="reserved.variables.session.html" class="classname">$_SESSION</a></var></var>. The older <var class="varname"><var class="varname">$HTTP_*_VARS</var></var> arrays, such as <var class="varname"><var class="varname">$HTTP_POST_VARS</var></var>, also exist. As of PHP 5.0.0, the long PHP <a href="language.variables.predefined.html" class="link">predefined variable</a> arrays may be disabled with the <a href="ini.core.html#ini.register-long-arrays" class="link">register_long_arrays</a> directive. </span> </li> <li class="listitem"> <span class="simpara"> External variables are no longer registered in the global scope by default. In other words, as of PHP <a href="http://www.php.net/releases/4_2_0.php" class="link external">» 4.2.0</a> the PHP directive <a href="ini.core.html#ini.register-globals" class="link">register_globals</a> is <em class="emphasis">off</em> by default in <var class="filename">php.ini</var>. The preferred method of accessing these values is via the superglobal arrays mentioned above. Older scripts, books, and tutorials may rely on this directive being <em>on</em>. If it were <em>on</em>, for example, one could use <var class="varname"><var class="varname">$id</var></var> from the URL <em>http://www.example.com/foo.php?id=42</em>. Whether on or off, <var class="varname"><var class="varname"><a href="reserved.variables.get.html" class="classname">$_GET['id']</a></var></var> is available. </span> </li> </ul> For more details on these changes, see the section on <a href="language.variables.predefined.html" class="link">predefined variables</a> and links therein. </p> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="tutorial.forms.html">Dealing with Forms</a></div> <div class="next" style="text-align: right; float: right;"><a href="tutorial.whatsnext.html">What's next?</a></div> <div class="up"><a href="tutorial.html">A simple tutorial</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>