downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Our source is open

The syntax highlighted source is automatically generated by PHP from the plaintext script. If you're interested in what's behind the several functions we used, you can always take a look at the source of the following files:

Of course, if you want to see the source of this page, we have it available. You can also browse the SVN repository for this website on svn.php.net.

Source of: /manual/en/migration5.incompatible.php

<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once
dirname(__FILE__) ."/toc/migration5.inc";
$setup = array (
 
'home' =>
  array (
   
0 => 'index.php',
   
1 => 'PHP Manual',
  ),
 
'head' =>
  array (
   
0 => 'UTF-8',
   
1 => 'en',
  ),
 
'this' =>
  array (
   
0 => 'migration5.incompatible.php',
   
1 => 'Backward Incompatible Changes',
  ),
 
'up' =>
  array (
   
0 => 'migration5.php',
   
1 => 'Migrating from PHP 4 to PHP 5.0.x',
  ),
 
'prev' =>
  array (
   
0 => 'migration5.changes.php',
   
1 => 'What has changed in PHP 5.0.x',
  ),
 
'next' =>
  array (
   
0 => 'migration5.cli-cgi.php',
   
1 => 'CLI and CGI',
  ),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);

manual_header();
?>
<div id="migration5.incompatible" class="section">
   <h2 class="title">Backward Incompatible Changes</h2>
   <p class="para">
    Although most existing PHP 4 code should work without changes, you should
    pay attention to the following backward incompatible changes:
   </p>
   <ul class="itemizedlist">
    <li class="listitem">
     <span class="simpara">
      There are some <a href="reserved.keywords.php" class="link">new reserved
      keywords</a>.
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      <a href="function.strrpos.php" class="function">strrpos()</a> and <a href="function.strripos.php" class="function">strripos()</a> now use
      the entire string as a needle.
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      Illegal use of string offsets causes <b><tt class="constant">E_ERROR</tt></b> instead
      of <b><tt class="constant">E_WARNING</tt></b>. An example illegal use is:
      <i>$str = &#039;abc&#039;; unset($str[0]);</i>.
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      <a href="function.array-merge.php" class="function">array_merge()</a> was changed to accept only arrays. If a
      non-array variable is passed, a <b><tt class="constant">E_WARNING</tt></b> will be
      thrown for every such parameter. Be careful because your code may start
      emitting <b><tt class="constant">E_WARNING</tt></b> out of the blue.
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      <b><tt class="constant">PATH_TRANSLATED</tt></b> server variable is no longer set implicitly under
      Apache2 SAPI in contrast to the situation in PHP 4, where it is set to
      the same value as the <b><tt class="constant">SCRIPT_FILENAME</tt></b> server variable when it is not
      populated by Apache. This change was made to comply with the <a href="http://hoohoo.ncsa.uiuc.edu/cgi/" class="link external">&raquo; CGI specification</a>. Please refer to <a href="http://bugs.php.net/23610" class="link external">&raquo; bug #23610</a> for further information,
      and see also the <var class="varname"><a href="reserved.variables.server.php" class="classname">$_SERVER['PATH_TRANSLATED']</a></var>
      description in the manual. This issue
      also affects PHP versions &gt;= 4.3.2.
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      The <b><tt class="constant">T_ML_COMMENT</tt></b> constant is no longer defined by
      the <a href="ref.tokenizer.php" class="link">Tokenizer</a> extension. If
      error_reporting is set to <b><tt class="constant">E_ALL</tt></b>, PHP will
      generate a notice. Although the <b><tt class="constant">T_ML_COMMENT</tt></b> was
      never used at all, it was defined in PHP 4. In both PHP 4 and PHP 5
      // and /* */ are resolved as the <b><tt class="constant">T_COMMENT</tt></b>
      constant. However the PHPDoc style comments <i>/** */</i>, which starting PHP
      5 are parsed by PHP, are recognized as <b><tt class="constant">T_DOC_COMMENT</tt></b>.
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      <var class="varname"><a href="reserved.variables.server.php" class="classname">$_SERVER</a></var> should be populated with <var class="varname">argc</var> and
      <var class="varname">argv</var> if
      <a href="ini.core.php#ini.variables-order" class="link">variables_order</a> includes &quot;S&quot;.
      If you have specifically configured your system to not create
      <var class="varname"><a href="reserved.variables.server.php" class="classname">$_SERVER</a></var>, then of course it shouldn&#039;t be there.
      The change was to always make <var class="varname">argc</var>
      and <var class="varname">argv</var> available in the CLI version regardless of the
      <a href="ini.core.php#ini.variables-order" class="link">variables_order</a> setting.
      As in, the CLI version will now always populate the global
      <var class="varname"><a href="reserved.variables.argc.php" class="classname">$argc</a></var> and <var class="varname"><a href="reserved.variables.argv.php" class="classname">$argv</a></var> variables.
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      An object with no properties is no longer considered &quot;empty&quot;.
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      In some cases classes must be declared before use. It only happens if
      some of the new features of PHP 5 (such as <a href="language.oop5.interfaces.php" class="link">interfaces</a>) are used.
      Otherwise the behaviour is the old.
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      <a href="function.get-class.php" class="function">get_class()</a>, <a href="function.get-parent-class.php" class="function">get_parent_class()</a>
      and <a href="function.get-class-methods.php" class="function">get_class_methods()</a> now return the name of the
      classes/methods as they were declared (case-sensitive) which may lead to
      problems in older scripts that rely on the previous behaviour (the
      class/method name was always returned lowercased). A possible solution
      is to search for those functions in all your scripts and use
      <a href="function.strtolower.php" class="function">strtolower()</a>.
     </span>
     <span class="simpara">
      This case sensitivity change also applies to the
      <a href="language.constants.predefined.php" class="link">magical predefined
      constants</a> <b><tt class="constant">__CLASS__</tt></b>,
      <b><tt class="constant">__METHOD__</tt></b>, and <b><tt class="constant">__FUNCTION__</tt></b>.
      The values are returned exactly as they&#039;re declared (case-sensitive).
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      <a href="function.ip2long.php" class="function">ip2long()</a> now returns <b><tt class="constant">FALSE</tt></b> when an invalid IP
      address is passed as argument to the function, and no longer
      <i>-1</i>.
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      If there are functions defined in the included file, they can be used in the
      main file independent if they are before <a href="function.return.php" class="function">return()</a> or after.
      If the file is included twice, PHP 5 issues fatal error because functions
      were already declared, while PHP 4 doesn&#039;t complain about it.
      It is recommended to use <a href="function.include-once.php" class="function">include_once()</a> instead of
      checking if the file was already included and conditionally return inside
      the included file.
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      <a href="function.include-once.php" class="function">include_once()</a> and <a href="function.require-once.php" class="function">require_once()</a>
      first normalize the path of included file on Windows so that including
      A.php and a.php include the file just once.
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      Passing an array to a function by value no longer resets the
      array&#039;s internal pointer for array accesses made within the
      function. In other words, in PHP 4 when you passed an array to a
      function, its internal pointer inside the function would be
      reset, while in PHP 5, when you pass an array to a function, its
      array pointer within the function will be wherever it was when
      the array was passed to the function.
     </span>
    </li>
   </ul>

   <p class="para">
    </p><div class="example">
     <p><b>Example #1 <a href="function.strrpos.php" class="function">strrpos()</a> and <a href="function.strripos.php" class="function">strripos()</a> now
      use the entire string as a needle</b></p>
     <div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">strrpos</span><span style="color: #007700">(</span><span style="color: #DD0000">'ABCDEF'</span><span style="color: #007700">,</span><span style="color: #DD0000">'DEF'</span><span style="color: #007700">));&nbsp;</span><span style="color: #FF8000">//int(3)<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">strrpos</span><span style="color: #007700">(</span><span style="color: #DD0000">'ABCDEF'</span><span style="color: #007700">,</span><span style="color: #DD0000">'DAF'</span><span style="color: #007700">));&nbsp;</span><span style="color: #FF8000">//bool(false)<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
     </div>

    </div><p>
   </p>
   <p class="para">
    </p><div class="example">
     <p><b>Example #2 An object with no properties is no longer considered &quot;empty&quot;</b></p>
     <div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">test&nbsp;</span><span style="color: #007700">{&nbsp;}<br /></span><span style="color: #0000BB">$t&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">test</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(empty(</span><span style="color: #0000BB">$t</span><span style="color: #007700">));&nbsp;</span><span style="color: #FF8000">//&nbsp;echo&nbsp;bool(false)<br /><br /></span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">$t</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Will&nbsp;be&nbsp;executed<br /></span><span style="color: #007700">}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
     </div>

    </div><p>
   </p>
   <p class="para">
    </p><div class="example">
     <p><b>Example #3 In some cases classes must be declared before used</b></p>
     <div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">//works&nbsp;with&nbsp;no&nbsp;errors:<br /></span><span style="color: #0000BB">$a&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">a</span><span style="color: #007700">();<br />class&nbsp;</span><span style="color: #0000BB">a&nbsp;</span><span style="color: #007700">{<br />}<br /><br /><br /></span><span style="color: #FF8000">//throws&nbsp;an&nbsp;error:<br /></span><span style="color: #0000BB">$a&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">b</span><span style="color: #007700">();<br /><br />interface&nbsp;</span><span style="color: #0000BB">c</span><span style="color: #007700">{<br />}<br />class&nbsp;</span><span style="color: #0000BB">b&nbsp;</span><span style="color: #007700">implements&nbsp;</span><span style="color: #0000BB">c&nbsp;</span><span style="color: #007700">{<br />}&nbsp;<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
     </div>

    </div><p>
   </p>
  </div><?php manual_footer(); ?>
 
show source | credits | sitemap | contact | advertising | mirror sites