Source of: /manual/en/tutorial.oldcode.php
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/tutorial.inc";
$setup = array (
'home' =>
array (
0 => 'index.php',
1 => 'PHP Manual',
),
'head' =>
array (
0 => 'UTF-8',
1 => 'en',
),
'this' =>
array (
0 => 'tutorial.oldcode.php',
1 => 'Using old code with new versions of PHP',
),
'up' =>
array (
0 => 'tutorial.php',
1 => 'A simple tutorial',
),
'prev' =>
array (
0 => 'tutorial.forms.php',
1 => 'Dealing with Forms',
),
'next' =>
array (
0 => 'tutorial.whatsnext.php',
1 => 'What\'s next?',
),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);
manual_header();
?>
<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:
</p><ul class="itemizedlist">
<li class="listitem">
<span class="simpara">
The deprecation of the old <var class="varname">$HTTP_*_VARS</var> arrays
(which need to be indicated as global when used inside a function or
method). The following
<a href="language.variables.superglobals.php" 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"><a href="reserved.variables.get.php" class="classname">$_GET</a></var>, <var class="varname"><a href="reserved.variables.post.php" class="classname">$_POST</a></var>,
<var class="varname"><a href="reserved.variables.cookies.php" class="classname">$_COOKIE</a></var>, <var class="varname"><a href="reserved.variables.server.php" class="classname">$_SERVER</a></var>,
<var class="varname"><a href="reserved.variables.files.php" class="classname">$_FILES</a></var>, <var class="varname"><a href="reserved.variables.environment.php" class="classname">$_ENV</a></var>,
<var class="varname"><a href="reserved.variables.request.php" class="classname">$_REQUEST</a></var>, and <var class="varname"><a href="reserved.variables.session.php" class="classname">$_SESSION</a></var>. The
older <var class="varname">$HTTP_*_VARS</var> arrays, such as
<var class="varname">$HTTP_POST_VARS</var>, also exist.
As of PHP 5.0.0, the long PHP
<a href="language.variables.predefined.php" class="link">predefined variable</a>
arrays may be disabled with the
<a href="ini.core.php#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.php#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 <i>on</i>. If it were <i>on</i>,
for example, one could use <var class="varname">$id</var> from the URL
<i>http://www.example.com/foo.php?id=42</i>. Whether on
or off, <var class="varname"><a href="reserved.variables.get.php" class="classname">$_GET['id']</a></var> is available.
</span>
</li>
</ul><p>
For more details on these changes, see the section on
<a href="language.variables.predefined.php" class="link">predefined variables</a>
and links therein.
</p>
</div><?php manual_footer(); ?>