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/migration51.oop.php

<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once
dirname(__FILE__) ."/toc/migration51.inc";
$setup = array (
 
'home' =>
  array (
   
0 => 'index.php',
   
1 => 'PHP Manual',
  ),
 
'head' =>
  array (
   
0 => 'UTF-8',
   
1 => 'en',
  ),
 
'this' =>
  array (
   
0 => 'migration51.oop.php',
   
1 => 'Class and object changes',
  ),
 
'up' =>
  array (
   
0 => 'migration51.php',
   
1 => 'Migrating from PHP 5.0.x to PHP 5.1.x',
  ),
 
'prev' =>
  array (
   
0 => 'migration51.integer-parameters.php',
   
1 => 'Integer values in function parameters',
  ),
 
'next' =>
  array (
   
0 => 'migration51.extensions.php',
   
1 => 'Extensions',
  ),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);

manual_header();
?>
<div id="migration51.oop" class="section">
  <h2 class="title">Class and object changes</h2>
  <ul class="itemizedlist">
   <li class="listitem">
    <p class="para">
     <a href="migration51.oop.php#migration51.oop-functions" class="link"><i>instanceof</i>,
      <i>is_a()</i>, <i>is_subclass_of()</i> and
      <i>catch</i></a>
    </p>
   </li>
   <li class="listitem">
    <p class="para">
     <a href="migration51.oop.php#migration51.oop-methods" class="link">Abstract private methods</a>
    </p>
   </li>
   <li class="listitem">
    <p class="para">
     <a href="migration51.oop.php#migration51.oop-modifiers" class="link">Access modifiers in
      interfaces</a>
    </p>
   </li>
   <li class="listitem">
    <p class="para">
     <a href="migration51.oop.php#migration51.oop-inheritance" class="link">Changes in inheritance
      rules</a>
    </p>
   </li>
   <li class="listitem">
    <p class="para">
     <a href="migration51.oop.php#migration51.oop-constants" class="link">Class constants</a>
    </p>
   </li>
  </ul>

  <div id="migration51.oop-functions" class="section">
   <h2 class="title"><i>instanceof</i>, <i>is_a()</i>,
    <i>is_subclass_of()</i> and <i>catch</i></h2>
   <p class="para">
    In PHP 5.0, <i>is_a()</i> was deprecated and replaced by the
    <i>instanceof</i> operator. There were some issues with the
    initial implementation of <i>instanceof</i>, which relied on
    <i>__autoload()</i> to search for missing classes.
    If the class was not present, <i>instanceof</i> would throw
    a fatal <b><tt class="constant">E_ERROR</tt></b> due to the failure of
    <i>__autoload()</i> to discover that class. The same behaviour
    occurred in the <i>catch</i> operator and the
    <i>is_subclass_of()</i> function, for the same reason.
   </p>
   <p class="para">
    None of these functions or operators call <i>__autoload()</i>
    in PHP 5.1.x, and the <i>class_exists()</i> workarounds used
    in code written for PHP 5.0.x, while not problematic in any way, are no
    longer necessary.
   </p>
  </div>

  <div id="migration51.oop-methods" class="section">
   <h2 class="title">Abstract private methods</h2>
   <p class="para">
    Abstract private methods were supported between PHP 5.0.0 and PHP 5.0.4,
    but were then disallowed on the grounds that the behaviours of
    <i>private</i> and <i>abstract</i> are mutually
    exclusive.
   </p>
  </div>

  <div id="migration51.oop-modifiers" class="section">
   <h2 class="title">Access modifiers in interfaces</h2>
   <p class="para">
    Under PHP 5.0, function declarations in interfaces were treated in exactly
    the same way as function declarations in classes. This has not been the
    case since October 2004, at which point only the <i>public</i>
    access modifier was allowed in interface function declarations. Since
    April 2005 - which pre-dates the PHP 5.0b1 release - the
    <i>static</i> modifier has also been allowed. However, the
    <i>protected</i> and <i>private</i> modifiers will
    now throw an <b><tt class="constant">E_ERROR</tt></b>, as will
    <i>abstract</i>. Note that this change should not affect your
    existing code, as none of these modifiers makes sense in the context of
    interfaces anyway.
   </p>
  </div>

  <div id="migration51.oop-inheritance" class="section">
   <h2 class="title">Changes in inheritance rules</h2>
   <p class="para">
    Under PHP 5.0, it was possible to have a function declaration in a derived
    class that did not match the declaration of the same function in the base
    class, e.g.
   </p>
   <div class="informalexample">
    <p class="para">
     This code will cause an <b><tt class="constant">E_STRICT</tt></b> error to be emitted
     under PHP 5.1.x.
    </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">Base&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;&amp;</span><span style="color: #0000BB">return_by_ref</span><span style="color: #007700">()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$r&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">$r</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br />class&nbsp;</span><span style="color: #0000BB">Derived&nbsp;</span><span style="color: #007700">extends&nbsp;</span><span style="color: #0000BB">Base&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;</span><span style="color: #0000BB">return_by_ref</span><span style="color: #007700">()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </div>

  <div id="migration51.oop-constants" class="section">
   <h2 class="title">Class constants</h2>
   <p class="para">
    Under PHP 5.0.x, the following code was valid:
   </p>
   <div class="informalexample">
    <p class="para">
     Under PHP 5.1.x, redefinition of a class constant will throw a fatal
     <b><tt class="constant">E_ERROR</tt></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">{<br />&nbsp;&nbsp;&nbsp;&nbsp;const&nbsp;</span><span style="color: #0000BB">foobar&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'foo'</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;const&nbsp;</span><span style="color: #0000BB">foobar&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'bar'</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

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