Sophie

Sophie

distrib > Mageia > 7 > x86_64 > by-pkgid > 2b917e0437961edec048f1d15e2d7449 > files > 9820

php-manual-en-7.2.11-1.mga7.noarch.rpm

<!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>Backward incompatible changes</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="migration70.html">Migrating from PHP 5.6.x to PHP 7.0.x</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="migration70.new-features.html">New features</a></div>
 <div class="up"><a href="migration70.html">Migrating from PHP 5.6.x to PHP 7.0.x</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="migration70.incompatible" class="sect1">
 <h2 class="title">Backward incompatible changes</h2>

 


<div class="sect2" id="migration70.incompatible.error-handling">
 <h3 class="title">Changes to error and exception handling</h3>

 <p class="para">
  Many fatal and recoverable fatal errors have been converted to exceptions in
  PHP 7. These error exceptions inherit from the <a href="class.error.html" class="classname">Error</a>
  class, which itself implements the <a href="class.throwable.html" class="classname">Throwable</a>
  interface (the new base interface all exceptions inherit).
 </p>

 <p class="para">
  This means that custom error handlers may no longer be triggered because
  exceptions may be thrown instead (causing new fatal errors for uncaught
  <a href="class.error.html" class="classname">Error</a> exceptions).
 </p>

 <p class="para">
  A fuller description of how errors operate in PHP 7 can be found
  <a href="language.errors.php7.html" class="link">on the PHP 7 errors page</a>. This
  migration guide will merely enumerate the changes that affect backward
  compatibility.
 </p>

 <div class="sect3" id="migration70.incompatible.error-handling.set-exception-handler">
  <h4 class="title">
   <span class="function"><a href="function.set-exception-handler.html" class="function">set_exception_handler()</a></span> is no longer guaranteed to
   receive <a href="class.exception.html" class="classname">Exception</a> objects
  </h4>

  <p class="para">
   Code that implements an exception handler registered with
   <span class="function"><a href="function.set-exception-handler.html" class="function">set_exception_handler()</a></span> using a type declaration of
   <a href="class.exception.html" class="classname">Exception</a> will cause a fatal error when an
   <a href="class.error.html" class="classname">Error</a> object is thrown.
  </p>

  <p class="para">
   If the handler needs to work on both PHP 5 and 7, you should remove the
   type declaration from the handler, while code that is being migrated to
   work on PHP 7 exclusively can simply replace the
   <a href="class.exception.html" class="classname">Exception</a> type declaration with
   <a href="class.throwable.html" class="classname">Throwable</a> instead.
  </p>

  <div class="informalexample">
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;PHP&nbsp;5&nbsp;era&nbsp;code&nbsp;that&nbsp;will&nbsp;break.<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">handler</span><span style="color: #007700">(</span><span style="color: #0000BB">Exception&nbsp;$e</span><span style="color: #007700">)&nbsp;{&nbsp;...&nbsp;}<br /></span><span style="color: #0000BB">set_exception_handler</span><span style="color: #007700">(</span><span style="color: #DD0000">'handler'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;PHP&nbsp;5&nbsp;and&nbsp;7&nbsp;compatible.<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">handler</span><span style="color: #007700">(</span><span style="color: #0000BB">$e</span><span style="color: #007700">)&nbsp;{&nbsp;...&nbsp;}<br /><br /></span><span style="color: #FF8000">//&nbsp;PHP&nbsp;7&nbsp;only.<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">handler</span><span style="color: #007700">(</span><span style="color: #0000BB">Throwable&nbsp;$e</span><span style="color: #007700">)&nbsp;{&nbsp;...&nbsp;}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
 </div>

 <div class="sect3" id="migration70.incompatible.error-handling.constructors">
  <h4 class="title">Internal constructors always throw exceptions on failure</h4>

  <p class="para">
   Previously, some internal classes would return <strong><code>NULL</code></strong> or an unusable object
   when the constructor failed. All internal classes will now throw an
   <a href="class.exception.html" class="classname">Exception</a> in this case in the same way that user
   classes already had to.
  </p>
 </div>

 <div class="sect3" id="migration70.incompatible.error-handling.parse">
  <h4 class="title">Parse errors throw <a href="class.parseerror.html" class="classname">ParseError</a></h4>

  <p class="para">
   Parser errors now throw a <a href="class.parseerror.html" class="classname">ParseError</a> object. Error
   handling for <span class="function"><a href="function.eval.html" class="function">eval()</a></span> should now include a <a href="language.exceptions.html#language.exceptions.catch" class="link"><em>catch</em></a> block
   that can handle this error.
  </p>
 </div>

 <div class="sect3" id="migration70.incompatible.error-handling.strict">
  <h4 class="title">E_STRICT notices severity changes</h4>

  <p class="para">
   All of the <strong><code>E_STRICT</code></strong> notices have been reclassified to
   other levels. <strong><code>E_STRICT</code></strong> constant is retained, so calls like
   <em>error_reporting(E_ALL|E_STRICT)</em> will not cause an error.
  </p>
  <p class="para">
   <table class="doctable table">
    <caption><strong><strong><code>E_STRICT</code></strong> notices severity changes</strong></caption>
     
      <thead>
       <tr>
        <th>Situation</th>
        <th>New level/behaviour</th>
       </tr>

      </thead>

      <tbody class="tbody">
       <tr>
        <td>Indexing by a resource</td>
        <td><strong><code>E_NOTICE</code></strong></td>
       </tr>

       <tr>
        <td>Abstract static methods</td>
        <td>Notice removed, triggers no error</td>
       </tr>

       <tr>
        <td>&quot;Redefining&quot; a constructor</td>
        <td>Notice removed, triggers no error</td>
       </tr>

       <tr>
        <td>Signature mismatch during inheritance</td>
        <td><strong><code>E_WARNING</code></strong></td>
       </tr>

       <tr>
        <td>Same (compatible) property in two used traits</td>
        <td>Notice removed, triggers no error</td>
       </tr>

       <tr>
        <td>Accessing static property non-statically</td>
        <td><strong><code>E_NOTICE</code></strong></td>
       </tr>

       <tr>
        <td>Only variables should be assigned by reference</td>
        <td><strong><code>E_NOTICE</code></strong></td>
       </tr>

       <tr>
        <td>Only variables should be passed by reference</td>
        <td><strong><code>E_NOTICE</code></strong></td>
       </tr>

       <tr>
        <td>Calling non-static methods statically</td>
        <td><strong><code>E_DEPRECATED</code></strong></td>
       </tr>

      </tbody>
     
    </table>

   </p>
 </div>
</div>



 


<div class="sect2" id="migration70.incompatible.variable-handling">
 <h3 class="title">Changes to variable handling</h3>

 <p class="para">
  PHP 7 now uses an abstract syntax tree when parsing source files. This has
  permitted many improvements to the language which were previously
  impossible due to limitations in the parser used in earlier versions of
  PHP, but has resulted in the removal of a few special cases for consistency
  reasons, which has resulted in backward compatibility breaks. These cases
  are detailed in this section.
 </p>

 <div class="sect3" id="migration70.incompatible.variable-handling.indirect">
  <h4 class="title">
   Changes to the handling of indirect variables, properties, and methods
  </h4>

  <p class="para">
   Indirect access to variables, properties, and methods will now be
   evaluated strictly in left-to-right order, as opposed to the previous mix
   of special cases. The table below shows how the order of evaluation has
   changed.
  </p>

  <p class="para">
   <table class="doctable table">
    <caption><strong>Old and new evaluation of indirect expressions</strong></caption>
    
     <thead>
      <tr>
       <th>Expression</th>
       <th>PHP 5 interpretation</th>
       <th>PHP 7 interpretation</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>
        <code class="code">$$foo[&#039;bar&#039;][&#039;baz&#039;]</code>
       </td>
       <td>
        <code class="code">${$foo[&#039;bar&#039;][&#039;baz&#039;]}</code>
       </td>
       <td>
        <code class="code">($$foo)[&#039;bar&#039;][&#039;baz&#039;]</code>
       </td>
      </tr>

      <tr>
       <td>
        <code class="code">$foo-&gt;$bar[&#039;baz&#039;]</code>
       </td>
       <td>
        <code class="code">$foo-&gt;{$bar[&#039;baz&#039;]}</code>
       </td>
       <td>
        <code class="code">($foo-&gt;$bar)[&#039;baz&#039;]</code>
       </td>
      </tr>

      <tr>
       <td>
        <code class="code">$foo-&gt;$bar[&#039;baz&#039;]()</code>
       </td>
       <td>
        <code class="code">$foo-&gt;{$bar[&#039;baz&#039;]}()</code>
       </td>
       <td>
        <code class="code">($foo-&gt;$bar)[&#039;baz&#039;]()</code>
       </td>
      </tr>

      <tr>
       <td>
        <code class="code">Foo::$bar[&#039;baz&#039;]()</code>
       </td>
       <td>
        <code class="code">Foo::{$bar[&#039;baz&#039;]}()</code>
       </td>
       <td>
        <code class="code">(Foo::$bar)[&#039;baz&#039;]()</code>
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>

  <p class="para">
   Code that used the old right-to-left evaluation order must be rewritten to
   explicitly use that evaluation order with curly braces (see the above
   middle column). This will make the code both forwards compatible with PHP
   7.x and backwards compatible with PHP 5.x.
  </p>

  <p class="para">
   This also affects the <a href="language.variables.scope.html#language.variables.scope.global" class="link"><em>global</em></a> keyword. The curly brace syntax can be
   used to emulate the previous behaviour if required:
  </p>

  <div class="informalexample">
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">f</span><span style="color: #007700">()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Valid&nbsp;in&nbsp;PHP&nbsp;5&nbsp;only.<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">global&nbsp;$</span><span style="color: #0000BB">$foo</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">bar</span><span style="color: #007700">;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Valid&nbsp;in&nbsp;PHP&nbsp;5&nbsp;and&nbsp;7.<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">global&nbsp;${</span><span style="color: #0000BB">$foo</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">bar</span><span style="color: #007700">};<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
 </div>

 <div class="sect3" id="migration70.incompatible.variable-handling.list">
  <h4 class="title">Changes to <span class="function"><a href="function.list.html" class="function">list()</a></span> handling</h4>

  <div class="sect4" id="migration70.incompatible.variable-handling.list.order">
   <h5 class="title">
    <span class="function"><a href="function.list.html" class="function">list()</a></span> no longer assigns variables in reverse order
   </h5>

   <p class="para">
    <span class="function"><a href="function.list.html" class="function">list()</a></span> will now assign values to variables in the
    order they are defined, rather than reverse order. In general, this only
    affects the case where <span class="function"><a href="function.list.html" class="function">list()</a></span> is being used in
    conjunction with the array <code class="code">[]</code> operator, as shown below:
   </p>

   <div class="informalexample">
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">list(</span><span style="color: #0000BB">$a</span><span style="color: #007700">[],&nbsp;</span><span style="color: #0000BB">$a</span><span style="color: #007700">[],&nbsp;</span><span style="color: #0000BB">$a</span><span style="color: #007700">[])&nbsp;=&nbsp;[</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">3</span><span style="color: #007700">];<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$a</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <p class="para">Output of the above example in PHP 5:</p>
    <div class="example-contents screen">
<div class="cdata"><pre>
array(3) {
  [0]=&gt;
  int(3)
  [1]=&gt;
  int(2)
  [2]=&gt;
  int(1)
}
</pre></div>
    </div>
    <p class="para">Output of the above example in PHP 7:</p>
    <div class="example-contents screen">
<div class="cdata"><pre>
array(3) {
  [0]=&gt;
  int(1)
  [1]=&gt;
  int(2)
  [2]=&gt;
  int(3)
}
</pre></div>
    </div>
   </div>

   <p class="para">
    In general, it is recommended not to rely on the order in which
    <span class="function"><a href="function.list.html" class="function">list()</a></span> assignments occur, as this is an implementation
    detail that may change again in the future.
   </p>
  </div>

  <div class="sect4" id="migration70.incompatible.variable-handling.list.empty">
   <h5 class="title">Empty <span class="function"><a href="function.list.html" class="function">list()</a></span> assignments have been removed</h5>

   <p class="para">
    <span class="function"><a href="function.list.html" class="function">list()</a></span> constructs can no longer be empty. The following
    are no longer allowed:
   </p>

   <div class="informalexample">
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">list()&nbsp;=&nbsp;</span><span style="color: #0000BB">$a</span><span style="color: #007700">;<br />list(,,)&nbsp;=&nbsp;</span><span style="color: #0000BB">$a</span><span style="color: #007700">;<br />list(</span><span style="color: #0000BB">$x</span><span style="color: #007700">,&nbsp;list(),&nbsp;</span><span style="color: #0000BB">$y</span><span style="color: #007700">)&nbsp;=&nbsp;</span><span style="color: #0000BB">$a</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </div>

  <div class="sect4" id="migration70.incompatible.variable-handling.list.string">
   <h5 class="title"><span class="function"><a href="function.list.html" class="function">list()</a></span> cannot unpack <span class="type"><a href="language.types.string.html" class="type string">string</a></span>s</h5>

   <p class="para">
    <span class="function"><a href="function.list.html" class="function">list()</a></span> can no longer unpack <span class="type"><a href="language.types.string.html" class="type string">string</a></span>
    variables. <span class="function"><a href="function.str-split.html" class="function">str_split()</a></span> should be used instead.
   </p>
  </div>
 </div>

 <div class="sect3" id="migration70.incompatible.variable-handling.array-order">
  <h4 class="title">
   Array ordering when elements are automatically created during by reference
   assignments has changed
  </h4>

  <p class="para">
   The order of the elements in an array has changed when those elements have
   been automatically created by referencing them in a by reference
   assignment. For example:
  </p>

  <div class="informalexample">
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$array&nbsp;</span><span style="color: #007700">=&nbsp;[];<br /></span><span style="color: #0000BB">$array</span><span style="color: #007700">[</span><span style="color: #DD0000">"a"</span><span style="color: #007700">]&nbsp;=&amp;&nbsp;</span><span style="color: #0000BB">$array</span><span style="color: #007700">[</span><span style="color: #DD0000">"b"</span><span style="color: #007700">];<br /></span><span style="color: #0000BB">$array</span><span style="color: #007700">[</span><span style="color: #DD0000">"b"</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$array</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <p class="para">Output of the above example in PHP 5:</p>
   <div class="example-contents screen">
<div class="cdata"><pre>
array(2) {
  [&quot;b&quot;]=&gt;
  &amp;int(1)
  [&quot;a&quot;]=&gt;
  &amp;int(1)
}
</pre></div>
   </div>
   <p class="para">Output of the above example in PHP 7:</p>
   <div class="example-contents screen">
<div class="cdata"><pre>
array(2) {
  [&quot;a&quot;]=&gt;
  &amp;int(1)
  [&quot;b&quot;]=&gt;
  &amp;int(1)
}
</pre></div>
   </div>
  </div>
 </div>

 <div class="sect3" id="migration70.incompatible.variable-handling.parentheses">
  <h4 class="title">
   Parentheses around function arguments no longer affect behaviour
  </h4>

  <p class="para">
   In PHP 5, using redundant parentheses around a function argument could
   quiet strict standards warnings when the function argument was passed by
   reference. The warning will now always be issued.
  </p>

  <div class="informalexample">
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">getArray</span><span style="color: #007700">()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;[</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">3</span><span style="color: #007700">];<br />}<br /><br />function&nbsp;</span><span style="color: #0000BB">squareArray</span><span style="color: #007700">(array&nbsp;&amp;</span><span style="color: #0000BB">$a</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;foreach&nbsp;(</span><span style="color: #0000BB">$a&nbsp;</span><span style="color: #007700">as&nbsp;&amp;</span><span style="color: #0000BB">$v</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$v&nbsp;</span><span style="color: #007700">**=&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;Generates&nbsp;a&nbsp;warning&nbsp;in&nbsp;PHP&nbsp;7.<br /></span><span style="color: #0000BB">squareArray</span><span style="color: #007700">((</span><span style="color: #0000BB">getArray</span><span style="color: #007700">()));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <p class="para">The above example will output:</p>
   <div class="example-contents screen">
<div class="cdata"><pre>
Notice: Only variables should be passed by reference in /tmp/test.php on line 13
</pre></div>
   </div>
  </div>
 </div>
</div>



 


<div class="sect2" id="migration70.incompatible.foreach">
 <h3 class="title">Changes to <a href="control-structures.foreach.html" class="link">foreach</a></h3>

 <p class="para">
  Minor changes have been made to the behaviour of the <a href="control-structures.foreach.html" class="link">foreach</a> control
  structure, primarily around the handling of the internal array pointer and
  modification of the array being iterated over.
 </p>

 <div class="sect3" id="migration70.incompatible.foreach.array-pointer">
  <h4 class="title"><a href="control-structures.foreach.html" class="link">foreach</a> no longer changes the internal array pointer</h4>

  <p class="para">
   Prior to PHP 7, the internal array pointer was modified while an array was
   being iterated over with <a href="control-structures.foreach.html" class="link">foreach</a>. This is no longer the case, as shown
   in the following example:
  </p>

  <div class="informalexample">
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$array&nbsp;</span><span style="color: #007700">=&nbsp;[</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">];<br />foreach&nbsp;(</span><span style="color: #0000BB">$array&nbsp;</span><span style="color: #007700">as&nbsp;&amp;</span><span style="color: #0000BB">$val</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">current</span><span style="color: #007700">(</span><span style="color: #0000BB">$array</span><span style="color: #007700">));<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <p class="para">Output of the above example in PHP 5:</p>
   <div class="example-contents screen">
<div class="cdata"><pre>
int(1)
int(2)
bool(false)
</pre></div>
   </div>
   <p class="para">Output of the above example in PHP 7:</p>
   <div class="example-contents screen">
<div class="cdata"><pre>
int(0)
int(0)
int(0)
</pre></div>
   </div>
  </div>
 </div>

 <div class="sect3" id="migration70.incompatible.foreach.by-value">
  <h4 class="title"><a href="control-structures.foreach.html" class="link">foreach</a> by-value operates on a copy of the array</h4>

  <p class="para">
   When used in the default by-value mode, <a href="control-structures.foreach.html" class="link">foreach</a> will now operate on a
   copy of the array being iterated rather than the array itself. This means
   that changes to the array made during iteration will not affect the values
   that are iterated.
  </p>
 </div>

 <div class="sect3" id="migration70.incompatible.foreach.by-ref">
  <h4 class="title"><a href="control-structures.foreach.html" class="link">foreach</a> by-reference has improved iteration behaviour</h4>

  <p class="para">
   When iterating by-reference, <a href="control-structures.foreach.html" class="link">foreach</a> will now do a better job of
   tracking changes to the array made during iteration. For example,
   appending to an array while iterating will now result in the appended
   values being iterated over as well:
  </p>

  <div class="informalexample">
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$array&nbsp;</span><span style="color: #007700">=&nbsp;[</span><span style="color: #0000BB">0</span><span style="color: #007700">];<br />foreach&nbsp;(</span><span style="color: #0000BB">$array&nbsp;</span><span style="color: #007700">as&nbsp;&amp;</span><span style="color: #0000BB">$val</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$val</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$array</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <p class="para">Output of the above example in PHP 5:</p>
   <div class="example-contents screen">
<div class="cdata"><pre>
int(0)
</pre></div>
   </div>
   <p class="para">Output of the above example in PHP 7:</p>
   <div class="example-contents screen">
<div class="cdata"><pre>
int(0)
int(1)
</pre></div>
   </div>
  </div>
 </div>

 <div class="sect3" id="migration70.incompatible.foreach.object">
  <h4 class="title">Iteration of non-<a href="class.traversable.html" class="classname">Traversable</a> objects</h4>

  <p class="para">
   Iterating over a non-<a href="class.traversable.html" class="classname">Traversable</a> object will now
   have the same behaviour as iterating over by-reference arrays. This
   results in the
   <a href="migration70.incompatible.html#migration70.incompatible.foreach.by-ref" class="link">improved behaviour when modifying an array during iteration</a>
   also being applied when properties are added to or removed from the
   object.
  </p>
 </div>
</div>



 


<div class="sect2" id="migration70.incompatible.integers">
 <h3 class="title">Changes to <span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span> handling</h3>

 <div class="sect3" id="migration70.incompatible.integers.invalid-octals">
  <h4 class="title">Invalid octal literals</h4>

  <p class="para">
   Previously, octal literals that contained invalid numbers were silently
   truncated (<em>0128</em> was taken as <em>012</em>).
   Now, an invalid octal literal will cause a parse error.
  </p>
 </div>

 <div class="sect3" id="migration70.incompatible.integers.negative-bitshift">
  <h4 class="title">Negative bitshifts</h4>

  <p class="para">
   Bitwise shifts by negative numbers will now throw an
   <a href="class.arithmeticerror.html" class="classname">ArithmeticError</a>:
  </p>
  <div class="informalexample">
   <div class="example-contents">
<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">1&nbsp;</span><span style="color: #007700">&gt;&gt;&nbsp;-</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

    <p class="para">Output of the above example in PHP 5:</p>
    <div class="example-contents screen">
<div class="cdata"><pre>
int(0)
</pre></div>
    </div>
    <p class="para">Output of the above example in PHP 7:</p>
    <div class="example-contents screen">
<div class="cdata"><pre>
Fatal error: Uncaught ArithmeticError: Bit shift by negative number in /tmp/test.php:2
Stack trace:
#0 {main}
  thrown in /tmp/test.php on line 2
</pre></div>
    </div>
  </div>
 </div>

 <div class="sect3" id="migration70.incompatible.integers.out-of-range">
  <h4 class="title">Out of range bitshifts</h4>

  <p class="para">
   Bitwise shifts (in either direction) beyond the bit width of an
   <span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span> will always result in 0. Previously, the behaviour of
   such shifts was architecture dependent.
  </p>
 </div>

 <div class="sect3" id="migration70.incompatible.integers.div-by-zero">
  <h4 class="title">Changes to Division By Zero</h4>

  <p class="para">
   Previously, when 0 was used as the divisor for either the divide (/) or
   modulus (%) operators, an E_WARNING would be emitted and
   <strong><code>false</code></strong> would be returned. Now, the divide operator
   returns a float as either +INF, -INF, or NAN, as specified by IEEE 754. The modulus operator E_WARNING
   has been removed and will throw a <a href="class.divisionbyzeroerror.html" class="classname">DivisionByZeroError</a>
   exception.
  </p>
  <div class="informalexample">
   <div class="example-contents">
<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">3</span><span style="color: #007700">/</span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">/</span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">%</span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <p class="para">Output of the above example in PHP 5:</p>
   <div class="example-contents screen">
<div class="cdata"><pre>
Warning: Division by zero in %s on line %d
bool(false)

Warning: Division by zero in %s on line %d
bool(false)

Warning: Division by zero in %s on line %d
bool(false)
</pre></div>
   </div>
   <p class="para">Output of the above example in PHP 7:</p>
   <div class="example-contents screen">
<div class="cdata"><pre>
Warning: Division by zero in %s on line %d
float(INF)

Warning: Division by zero in %s on line %d
float(NAN)

PHP Fatal error:  Uncaught DivisionByZeroError: Modulo by zero in %s line %d
</pre></div>
   </div>
  </div>
 </div>
</div>



 


<div class="sect2" id="migration70.incompatible.strings">
 <h3 class="title">Changes to <span class="type"><a href="language.types.string.html" class="type string">string</a></span> handling</h3>

 <div class="sect3" id="migration70.incompatible.strings.hex">
  <h4 class="title">Hexadecimal strings are no longer considered numeric</h4>

  <p class="para">
   Strings containing hexadecimal numbers are no longer considered to be
   numeric. For example:
  </p>

  <div class="informalexample">
   <div class="example-contents">
<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: #DD0000">"0x123"&nbsp;</span><span style="color: #007700">==&nbsp;</span><span style="color: #DD0000">"291"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">is_numeric</span><span style="color: #007700">(</span><span style="color: #DD0000">"0x123"</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #DD0000">"0xe"&nbsp;</span><span style="color: #007700">+&nbsp;</span><span style="color: #DD0000">"0x1"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">substr</span><span style="color: #007700">(</span><span style="color: #DD0000">"foo"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"0x1"</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <p class="para">Output of the above example in PHP 5:</p>
   <div class="example-contents screen">
<div class="cdata"><pre>
bool(true)
bool(true)
int(15)
string(2) &quot;oo&quot;
</pre></div>
   </div>
   <p class="para">Output of the above example in PHP 7:</p>
   <div class="example-contents screen">
<div class="cdata"><pre>
bool(false)
bool(false)
int(0)

Notice: A non well formed numeric value encountered in /tmp/test.php on line 5
string(3) &quot;foo&quot;
</pre></div>
   </div>
  </div>

  <p class="para">
   <span class="function"><a href="function.filter-var.html" class="function">filter_var()</a></span> can be used to check if a
   <span class="type"><a href="language.types.string.html" class="type string">string</a></span> contains a hexadecimal number, and also to convert a
   string of that type to an <span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>:
  </p>

  <div class="informalexample">
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$str&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"0xffff"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$int&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">filter_var</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">FILTER_VALIDATE_INT</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">FILTER_FLAG_ALLOW_HEX</span><span style="color: #007700">);<br />if&nbsp;(</span><span style="color: #0000BB">false&nbsp;</span><span style="color: #007700">===&nbsp;</span><span style="color: #0000BB">$int</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;throw&nbsp;new&nbsp;</span><span style="color: #0000BB">Exception</span><span style="color: #007700">(</span><span style="color: #DD0000">"Invalid&nbsp;integer!"</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$int</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">//&nbsp;int(65535)<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
 </div>

 <div class="sect3" id="migration70.incompatible.strings.unicode-escapes">
  <h4 class="title"><em>\u{</em> may cause errors</h4>

  <p class="para">
   Due to the addition of the new
   <a href="migration70.new-features.html#migration70.new-features.unicode-codepoint-escape-syntax" class="link">Unicode codepoint escape syntax</a>,
   strings containing a literal <em>\u{</em> followed by an invalid
   sequence will cause a fatal error. To avoid this, the leading backslash
   should be escaped.
  </p>
 </div>
</div>



 


<div class="sect2" id="migration70.incompatible.removed-functions">
 <h3 class="title">Removed functions</h3>

 <div class="sect3" id="migration70.incompatible.removed-functions.call-user-method">
  <h4 class="title">
   <span class="function"><a href="function.call-user-method.html" class="function">call_user_method()</a></span> and
   <span class="function"><a href="function.call-user-method-array.html" class="function">call_user_method_array()</a></span>
  </h4>

  <p class="para">
   These functions were deprecated in PHP 4.1.0 in favour of
   <span class="function"><a href="function.call-user-func.html" class="function">call_user_func()</a></span> and
   <span class="function"><a href="function.call-user-func-array.html" class="function">call_user_func_array()</a></span>. You may also want to consider
   using
   <a href="functions.variable-functions.html" class="link">variable functions</a>
   and/or the
   <a href="functions.arguments.html#functions.variable-arg-list.new" class="link"><em>...</em></a>
   operator.
  </p>
 </div>

 <div class="sect3" id="migration70.incompatible.removed-functions.ereg">
  <h4 class="title">
   All ereg* functions
  </h4>
  <p class="para">
   All <a href="book.regex.html" class="link">ereg</a> functions were removed. 
   <a href="book.pcre.html" class="link">PCRE</a> is a recommended alternative.
  </p>
 </div>

 <div class="sect3" id="migration70.incompatible.removed-functions.mcrypt">
  <h4 class="title"><a href="book.mcrypt.html" class="link">mcrypt</a> aliases</h4>

  <p class="para">
   The deprecated <span class="function"><a href="function.mcrypt-generic-end.html" class="function">mcrypt_generic_end()</a></span> function has been
   removed in favour of <span class="function"><a href="function.mcrypt-generic-deinit.html" class="function">mcrypt_generic_deinit()</a></span>.
  </p>

  <p class="para">
   Additionally, the deprecated <span class="function"><a href="function.mcrypt-ecb.html" class="function">mcrypt_ecb()</a></span>,
   <span class="function"><a href="function.mcrypt-cbc.html" class="function">mcrypt_cbc()</a></span>, <span class="function"><a href="function.mcrypt-cfb.html" class="function">mcrypt_cfb()</a></span> and
   <span class="function"><a href="function.mcrypt-ofb.html" class="function">mcrypt_ofb()</a></span> functions have been removed in favour of
   using <span class="function"><a href="function.mcrypt-decrypt.html" class="function">mcrypt_decrypt()</a></span> with the appropriate
   <strong><code>MCRYPT_MODE_*</code></strong> constant.
  </p>
 </div>

 <div class="sect3" id="migration70.incompatible.removed-functions.mysql">
  <h4 class="title">
   All ext/mysql functions
  </h4>
  <p class="para">
   All <a href="book.mysql.html" class="link">ext/mysql</a> functions were removed. For
   details about choosing a different MySQL API, see
   <a href="mysqlinfo.api.choosing.html" class="link">Choosing a MySQL API</a>.
  </p>
 </div>

 <div class="sect3" id="migration70.incompatible.removed-functions.mssql">
  <h4 class="title">
   All ext/mssql functions
  </h4>
  <p class="para">
   All <a href="book.mssql.html" class="link">ext/mssql</a> functions were removed.
   For a list of alternatives, see the
   <a href="intro.mssql.html" class="link">MSSQL Introduction</a>.
  </p>
 </div>

 <div class="sect3" id="migration70.incompatible.removed-functions.intl">
  <h4 class="title"><a href="book.intl.html" class="link">intl</a> aliases</h4>

  <p class="para">
   The deprecated <span class="function"><a href="intldateformatter.settimezoneid.html" class="function">datefmt_set_timezone_id()</a></span> and
   <span class="methodname"><a href="intldateformatter.settimezoneid.html" class="methodname">IntlDateFormatter::setTimeZoneID()</a></span> aliases have been
   removed in favour of <span class="function"><a href="intldateformatter.settimezone.html" class="function">datefmt_set_timezone()</a></span> and
   <span class="methodname"><a href="intldateformatter.settimezone.html" class="methodname">IntlDateFormatter::setTimeZone()</a></span>, respectively.
  </p>
 </div>

 <div class="sect3" id="migration70.incompatible.removed-functions.magic-quotes">
  <h4 class="title"><span class="function"><a href="function.set-magic-quotes-runtime.html" class="function">set_magic_quotes_runtime()</a></span></h4>

  <p class="para">
   <span class="function"><a href="function.set-magic-quotes-runtime.html" class="function">set_magic_quotes_runtime()</a></span>, along with its alias
   <span class="function"><a href="function.magic-quotes-runtime.html" class="function">magic_quotes_runtime()</a></span>, have been removed. They were
   deprecated in PHP 5.3.0, and became effectively non-functional with the
   removal of magic quotes
   <a href="migration54.incompatible.html" class="link">in PHP 5.4.0</a>.
  </p>
 </div>

 <div class="sect3" id="migration70.incompatible.removed-functions.set-socket-blocking">
  <h4 class="title"><span class="function"><a href="function.set-socket-blocking.html" class="function">set_socket_blocking()</a></span></h4>

  <p class="para">
   The deprecated <span class="function"><a href="function.set-socket-blocking.html" class="function">set_socket_blocking()</a></span> alias has been
   removed in favour of <span class="function"><a href="function.stream-set-blocking.html" class="function">stream_set_blocking()</a></span>.
  </p>
 </div>

 <div class="sect3" id="migration70.incompatible.removed-functions.dl">
  <h4 class="title"><span class="function"><a href="function.dl.html" class="function">dl()</a></span> in PHP-FPM</h4>

  <p class="para">
   <span class="function"><a href="function.dl.html" class="function">dl()</a></span> can no longer be used in PHP-FPM. It remains
   functional in the CLI and embed SAPIs.
  </p>
 </div>

 <div class="sect3" id="migration70.incompatible.removed-functions.gd">
  <h4 class="title"><a href="book.image.html" class="link">GD</a> Type1 functions</h4>

  <p class="para">
   Support for PostScript Type1 fonts has been removed from the GD extension,
   resulting in the removal of the following functions:
  </p>

  <ul class="itemizedlist">
   <li class="listitem">
    <span class="simpara">
     <span class="function"><a href="function.imagepsbbox.html" class="function">imagepsbbox()</a></span>
    </span>
   </li>
   <li class="listitem">
    <span class="simpara">
     <span class="function"><a href="function.imagepsencodefont.html" class="function">imagepsencodefont()</a></span>
    </span>
   </li>
   <li class="listitem">
    <span class="simpara">
     <span class="function"><a href="function.imagepsextendfont.html" class="function">imagepsextendfont()</a></span>
    </span>
   </li>
   <li class="listitem">
    <span class="simpara">
     <span class="function"><a href="function.imagepsfreefont.html" class="function">imagepsfreefont()</a></span>
    </span>
   </li>
   <li class="listitem">
    <span class="simpara">
     <span class="function"><a href="function.imagepsloadfont.html" class="function">imagepsloadfont()</a></span>
    </span>
   </li>
   <li class="listitem">
    <span class="simpara">
     <span class="function"><a href="function.imagepsslantfont.html" class="function">imagepsslantfont()</a></span>
    </span>
   </li>
   <li class="listitem">
    <span class="simpara">
     <span class="function"><a href="function.imagepstext.html" class="function">imagepstext()</a></span>
    </span>
   </li>
  </ul>

  <p class="para">
   Using TrueType fonts and their associated functions is recommended instead.
  </p>
 </div>
</div>



 


<div class="sect2" id="migration70.incompatible.removed-ini-directives">
 <h3 class="title">Removed INI directives</h3>

 <div class="sect3" id="migration70.incompatible.removed-ini-directives.features">
  <h4 class="title">Removed features</h4>

  <p class="para">
   The following INI directives have been removed as their associated features
   have also been removed:
  </p>

  <ul class="itemizedlist">
   <li class="listitem">
    <span class="simpara">
     <a href="ini.core.html#ini.always-populate-raw-post-data" class="link"><code class="parameter">always_populate_raw_post_data</code></a>
    </span>
   </li>
   <li class="listitem">
    <span class="simpara">
     <a href="ini.core.html#ini.asp-tags" class="link"><code class="parameter">asp_tags</code></a>
    </span>
   </li>
  </ul>
 </div>

 <div class="sect3" id="migration70.incompatible.removed-ini-directives.xsl">
  <h4 class="title"><code class="parameter">xsl.security_prefs</code></h4>

  <p class="para">
   The <code class="parameter">xsl.security_prefs</code> directive has been removed.
   Instead, the <span class="methodname"><a href="xsltprocessor.setsecurityprefs.html" class="methodname">XsltProcessor::setSecurityPrefs()</a></span>
   method should be called to control the security preferences on a
   per-processor basis.
  </p>
 </div>
</div>



 


<div class="sect2" id="migration70.incompatible.other">
 <h3 class="title">Other backward incompatible changes</h3>

 <div class="sect3" id="migration70.incompatible.other.new-by-ref">
  <h4 class="title">New objects cannot be assigned by reference</h4>

  <p class="para">
   The result of the <a href="language.oop5.basic.html#language.oop5.basic.new" class="link"><em>new</em></a> statement can no longer be assigned to a variable
   by reference:
  </p>

  <div class="informalexample">
   <div class="example-contents">
<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">C&nbsp;</span><span style="color: #007700">{}<br /></span><span style="color: #0000BB">$c&nbsp;</span><span style="color: #007700">=&amp;&nbsp;new&nbsp;</span><span style="color: #0000BB">C</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <p class="para">Output of the above example in PHP 5:</p>
   <div class="example-contents screen">
<div class="cdata"><pre>
Deprecated: Assigning the return value of new by reference is deprecated in /tmp/test.php on line 3
</pre></div>
   </div>
   <p class="para">Output of the above example in PHP 7:</p>
   <div class="example-contents screen">
<div class="cdata"><pre>
Parse error: syntax error, unexpected &#039;new&#039; (T_NEW) in /tmp/test.php on line 3
</pre></div>
   </div>
  </div>
 </div>

 <div class="sect3" id="migration70.incompatible.other.classes">
  <h4 class="title">Invalid class, interface and trait names</h4>

  <p class="para">
   The following names cannot be used to name classes, interfaces or traits:
  </p>

  <ul class="itemizedlist">
   <li class="listitem">
    <span class="simpara"><span class="type"><a href="language.types.boolean.html" class="type bool">bool</a></span></span>
   </li>
   <li class="listitem">
    <span class="simpara"><span class="type"><a href="language.types.integer.html" class="type int">int</a></span></span>
   </li>
   <li class="listitem">
    <span class="simpara"><span class="type"><a href="language.types.float.html" class="type float">float</a></span></span>
   </li>
   <li class="listitem">
    <span class="simpara"><span class="type"><a href="language.types.string.html" class="type string">string</a></span></span>
   </li>
   <li class="listitem">
    <span class="simpara"><strong><code>NULL</code></strong></span>
   </li>
   <li class="listitem">
    <span class="simpara"><strong><code>TRUE</code></strong></span>
   </li>
   <li class="listitem">
    <span class="simpara"><strong><code>FALSE</code></strong></span>
   </li>
  </ul>

  <p class="para">
   Furthermore, the following names should not be used. Although they will not
   generate an error in PHP 7.0, they are reserved for future use and should
   be considered deprecated.
  </p>

  <ul class="itemizedlist">
   <li class="listitem">
    <span class="simpara"><span class="type"><a href="language.types.resource.html" class="type resource">resource</a></span></span>
   </li>
   <li class="listitem">
    <span class="simpara"><span class="type"><a href="language.types.object.html" class="type object">object</a></span></span>
   </li>
   <li class="listitem">
    <span class="simpara"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span></span>
   </li>
   <li class="listitem">
    <span class="simpara"><span class="type"><span class="type numeric">numeric</span></span></span>
   </li>
  </ul>
 </div>

 <div class="sect3" id="migration70.incompatible.other.php-tags">
  <h4 class="title">ASP and script PHP tags removed</h4>

  <p class="para">
   Support for using ASP and script tags to delimit PHP code has been removed.
   The affected tags are:
  </p>

  <table class="doctable table">
   <caption><strong>Removed ASP and script tags</strong></caption>
   
    <thead>
     <tr>
      <th>Opening tag</th>
      <th>Closing tag</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td><code class="code">&lt;%</code></td>
      <td><code class="code">%&gt;</code></td>
     </tr>

     <tr>
      <td><code class="code">&lt;%=</code></td>
      <td><code class="code">%&gt;</code></td>
     </tr>

     <tr>
      <td><code class="code">&lt;script language=&quot;php&quot;&gt;</code></td>
      <td><code class="code">&lt;/script&gt;</code></td>
     </tr>

    </tbody>
   
  </table>

 </div>

 <div class="sect3" id="migration70.incompatible.other.incompatible-this">
  <h4 class="title">Calls from incompatible context removed</h4>

  <p class="para">
   <a href="migration56.deprecated.html#migration56.deprecated.incompatible-context" class="link">Previously deprecated in PHP 5.6</a>,
   static calls made to a non-static method with an incompatible context will
   now result in the called method having an undefined
   <em>$this</em> variable and a deprecation warning being issued.
  </p>

  <div class="informalexample">
   <div class="example-contents">
<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">A&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">test</span><span style="color: #007700">()&nbsp;{&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$this</span><span style="color: #007700">);&nbsp;}<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;Note:&nbsp;Does&nbsp;NOT&nbsp;extend&nbsp;A<br /></span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">B&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">callNonStaticMethodOfA</span><span style="color: #007700">()&nbsp;{&nbsp;</span><span style="color: #0000BB">A</span><span style="color: #007700">::</span><span style="color: #0000BB">test</span><span style="color: #007700">();&nbsp;}<br />}<br /><br />(new&nbsp;</span><span style="color: #0000BB">B</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">callNonStaticMethodOfA</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <p class="para">Output of the above example in PHP 5.6:</p>
   <div class="example-contents screen">
<div class="cdata"><pre>
Deprecated: Non-static method A::test() should not be called statically, assuming $this from incompatible context in /tmp/test.php on line 8
object(B)#1 (0) {
}
</pre></div>
   </div>
   <p class="para">Output of the above example in PHP 7:</p>
   <div class="example-contents screen">
<div class="cdata"><pre>
Deprecated: Non-static method A::test() should not be called statically in /tmp/test.php on line 8

Notice: Undefined variable: this in /tmp/test.php on line 3
NULL
</pre></div>
   </div>
  </div>
 </div>

 <div class="sect3" id="migration70.incompatible.other.yield">
  <h4 class="title"><a href="language.generators.syntax.html#control-structures.yield" class="link">yield</a> is now a right associative operator</h4>

  <p class="para">
   The <a href="language.generators.syntax.html#control-structures.yield" class="link">yield</a> construct no longer requires parentheses, and has been changed
   to a right associative operator with precedence between
   <em>print</em> and <em>=&gt;</em>. This can result in
   changed behaviour:
  </p>

  <div class="informalexample">
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">yield&nbsp;</span><span style="color: #007700">-</span><span style="color: #0000BB">1</span><span style="color: #007700">;<br /></span><span style="color: #FF8000">//&nbsp;Was&nbsp;previously&nbsp;interpreted&nbsp;as<br /></span><span style="color: #007700">echo&nbsp;(</span><span style="color: #0000BB">yield</span><span style="color: #007700">)&nbsp;-&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">;<br /></span><span style="color: #FF8000">//&nbsp;And&nbsp;is&nbsp;now&nbsp;interpreted&nbsp;as<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">yield&nbsp;</span><span style="color: #007700">(-</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">yield&nbsp;$foo&nbsp;</span><span style="color: #007700">or&nbsp;die;<br /></span><span style="color: #FF8000">//&nbsp;Was&nbsp;previously&nbsp;interpreted&nbsp;as<br /></span><span style="color: #0000BB">yield&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">$foo&nbsp;</span><span style="color: #007700">or&nbsp;die);<br /></span><span style="color: #FF8000">//&nbsp;And&nbsp;is&nbsp;now&nbsp;interpreted&nbsp;as<br /></span><span style="color: #007700">(</span><span style="color: #0000BB">yield&nbsp;$foo</span><span style="color: #007700">)&nbsp;or&nbsp;die;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>

  <p class="para">
   Parentheses can be used to disambiguate those cases.
  </p>
 </div>

 <div class="sect3" id="migration70.incompatible.other.func-parameters">
  <h4 class="title">Functions cannot have multiple parameters with the same name</h4>

  <p class="para">
   It is no longer possible to define two or more function parameters with the
   same name. For example, the following function will trigger an
   <strong><code>E_COMPILE_ERROR</code></strong>:
  </p>

  <div class="informalexample">
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">foo</span><span style="color: #007700">(</span><span style="color: #0000BB">$a</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$b</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$unused</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$unused</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//<br /></span><span style="color: #007700">}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
 </div>

 <div class="sect3" id="migration70.incompatible.other.func-parameter-modified">
  <h4 class="title">Functions inspecting arguments report the <em class="emphasis">current</em> parameter value</h4>

  <p class="para">
   <span class="function"><a href="function.func-get-arg.html" class="function">func_get_arg()</a></span>, <span class="function"><a href="function.func-get-args.html" class="function">func_get_args()</a></span>,
   <span class="function"><a href="function.debug-backtrace.html" class="function">debug_backtrace()</a></span> and exception backtraces will no longer
   report the original value that was passed to a parameter, but will instead
   provide the current value (which might have been modified).
  </p>

  <div class="informalexample">
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">foo</span><span style="color: #007700">(</span><span style="color: #0000BB">$x</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$x</span><span style="color: #007700">++;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">func_get_arg</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">));<br />}<br /></span><span style="color: #0000BB">foo</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">);</span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <p class="para">Output of the above example in PHP 5:</p>
   <div class="example-contents screen">
<div class="cdata"><pre>
1
</pre></div>
   </div>
   <p class="para">Output of the above example in PHP 7:</p>
   <div class="example-contents screen">
<div class="cdata"><pre>
2
</pre></div>
   </div>
  </div>
 </div>

 <div class="sect3" id="migration70.incompatible.other.multiple-default">
  <h4 class="title">Switch statements cannot have multiple default blocks</h4>

  <p class="para">
   It is no longer possible to define two or more default blocks in a switch
   statement. For example, the following switch statement will trigger an
   <strong><code>E_COMPILE_ERROR</code></strong>:
  </p>

  <div class="informalexample">
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">switch&nbsp;(</span><span style="color: #0000BB">1</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;default:<br />&nbsp;&nbsp;&nbsp;&nbsp;break;<br />&nbsp;&nbsp;&nbsp;&nbsp;default:<br />&nbsp;&nbsp;&nbsp;&nbsp;break;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
 </div>

 <div class="sect3" id="migration70.incompatible.other.http-raw-post-data">
  <h4 class="title"><var class="varname"><var class="varname"><a href="reserved.variables.httprawpostdata.html" class="classname">$HTTP_RAW_POST_DATA</a></var></var> removed</h4>

  <p class="para">
   <var class="varname"><var class="varname"><a href="reserved.variables.httprawpostdata.html" class="classname">$HTTP_RAW_POST_DATA</a></var></var> is no longer available. The
   <a href="wrappers.php.html#wrappers.php.input" class="link"><em>php://input</em></a>
   stream should be used instead.
  </p>
 </div>

 <div class="sect3" id="migration70.incompatible.other.ini-comments">
  <h4 class="title"><em>#</em> comments in INI files removed</h4>

  <p class="para">
   Support for prefixing comments with <em>#</em> in INI files has been
   removed. <em>;</em> (semi-colon) should be used instead. This change
   applies to <var class="filename">php.ini</var>, as well as files handled by
   <span class="function"><a href="function.parse-ini-file.html" class="function">parse_ini_file()</a></span> and <span class="function"><a href="function.parse-ini-string.html" class="function">parse_ini_string()</a></span>.
  </p>
 </div>

 <div class="sect3" id="migration70.incompatible.other.json-to-jsond">
  <h4 class="title">JSON extension replaced with JSOND</h4>

  <p class="para">
   The JSON extension has been replaced with JSOND, causing three minor BC
   breaks. Firstly, a number must not end in a decimal point (i.e.
   <em>34.</em> must be changed to either <em>34.0</em> or
   <em>34</em>). Secondly, when using scientific notation, the
   <em>e</em> exponent must not immediately follow a decimal point
   (i.e. <em>3.e3</em> must be changed to either
   <em>3.0e3</em> or <em>3e3</em>).
   Finally, an empty string is no longer considered valid JSON.
  </p>
 </div>

 <div class="sect3" id="migration70.incompatible.other.internal-function-failure-overflow">
  <h4 class="title">Internal function failure on overflow</h4>

  <p class="para">
   Previously, internal functions would silently truncate numbers produced from
   float-to-integer coercions when the float was too large to represent as an
   integer. Now, an E_WARNING will be emitted and <strong><code>NULL</code></strong> will be returned.
  </p>
 </div>

 <div class="sect3" id="migration70.incompatible.other.fixes-custom-session-handler">
  <h4 class="title">Fixes to custom session handler return values</h4>

  <p class="para">
   Any predicate functions implemented by custom session handlers that return
   either <strong><code>FALSE</code></strong> or <em>-1</em> will be fatal errors. If any value
   from these functions other than a boolean, <em>-1</em>, or
   <em>0</em> is returned, then it will fail and an E_WARNING will be
   emitted.
  </p>
 </div>

 <div class="sect3" id="migration70.incompatible.other.sort-order">
  <h4 class="title">Sort order of equal elements</h4>
  <p class="para">
   The internal sorting algorithm has been improved, what may result in
   different sort order of elements, which compare as equal, than before.
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    Don&#039;t rely on the order of elements which compare as equal; it might change
    anytime.
   </p>
  </p></blockquote>
 </div>

 <div class="sect3" id="migration70.incompatible.other.mhash">
  <h4 class="title">Mhash is not an extension anymore</h4>
  <p class="para">
   The Mhash extension has been fully integrated into the <a href="book.hash.html" class="link">Hash</a> extension. Therefore, it is no longer
   possible to detect Mhash support with <span class="function"><a href="function.extension-loaded.html" class="function">extension_loaded()</a></span>;
   use <span class="function"><a href="function.function-exists.html" class="function">function_exists()</a></span> instead. Furthermore, Mhash is no
   longer reported by <span class="function"><a href="function.get-loaded-extensions.html" class="function">get_loaded_extensions()</a></span> and related
   features.
  </p>
 </div>
</div>



</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="migration70.html">Migrating from PHP 5.6.x to PHP 7.0.x</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="migration70.new-features.html">New features</a></div>
 <div class="up"><a href="migration70.html">Migrating from PHP 5.6.x to PHP 7.0.x</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>