<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/migration70.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'de',
  ),
  'this' => 
  array (
    0 => 'migration70.new-features.php',
    1 => 'Neue Features',
    2 => 'Neue Features',
  ),
  'up' => 
  array (
    0 => 'migration70.php',
    1 => 'Migration von PHP 5.6.x nach PHP 7.0.x',
  ),
  'prev' => 
  array (
    0 => 'migration70.incompatible.php',
    1 => 'Nicht abw&auml;rtskompatible &Auml;nderungen',
  ),
  'next' => 
  array (
    0 => 'migration70.deprecated.php',
    1 => 'Veraltete Features in PHP 7.0.x',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'de',
    'path' => 'appendices/migration70/new-features.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="migration70.new-features" class="sect1">
 <h2 class="title">Neue Features</h2>

 <div class="sect2" id="migration70.new-features.scalar-type-declarations">
  <h3 class="title">Deklaration skalarer Typen</h3>

  <p class="para">
   Für die
   <a href="language.types.declarations.php" class="link">Deklaration des Typs</a> von
   Skalaren gibt es zwei Möglichkeiten: erzwungen (Standard) und strikt. Die
   folgenden Typen können nun für Parameter erzwungen werden: Zeichenketten
   (<span class="type"><a href="language.types.string.php" class="type string">string</a></span>), Ganzzahlen (<code class="literal">int</code>), Gleitkommazahlen
   (<span class="type"><a href="language.types.float.php" class="type float">float</a></span>), und Booleans (<code class="literal">bool</code>). Sie ergänzen
   die anderen in PHP 5 eingeführten Typen: Klassennamen, Schnittstellen,
   <span class="type"><a href="language.types.array.php" class="type array">array</a></span> und <span class="type"><a href="language.types.callable.php" class="type callable">callable</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 /></span><span style="color: #FF8000">// Erzwingender Modus<br /></span><span style="color: #007700">function </span><span style="color: #0000BB">sumOfInts</span><span style="color: #007700">(</span><span style="color: #0000BB">int </span><span style="color: #007700">...</span><span style="color: #0000BB">$ints</span><span style="color: #007700">)<br />{<br />    return </span><span style="color: #0000BB">array_sum</span><span style="color: #007700">(</span><span style="color: #0000BB">$ints</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">sumOfInts</span><span style="color: #007700">(</span><span style="color: #0000BB">2</span><span style="color: #007700">, </span><span style="color: #DD0000">'3'</span><span style="color: #007700">, </span><span style="color: #0000BB">4.1</span><span style="color: #007700">));</span></span></code></div>
   </div>

   <p class="para">Das oben gezeigte Beispiel erzeugt folgende Ausgabe:</p>
   <div class="example-contents screen">
<div class="cdata"><pre>
int(9)
</pre></div>
   </div>
  </div>

  <p class="para">
   Um den strikten Modus zu aktivieren, muss am Anfang der Datei eine einzelne
   <a href="control-structures.declare.php" class="link"><code class="literal">declare</code></a>-Direktive stehen. Das bedeutet, dass die Strenge der Typisierung
   für Skalare für jede Datei einzeln festgelegt wird. Diese Anweisung wirkt
   sich nicht nur auf die Typ-Deklarationen von Parametern aus, sondern auch
   auf den Rückgabetyp von Funktionen (siehe
   <a href="language.types.declarations.php" class="link">Deklaration des Rückgabetyps</a>),
   auf eingebaute PHP-Funktionen und auf Funktionen von geladenen Erweiterungen.
  </p>

  <p class="para">
   Eine vollständige Dokumentation und Beispiele für die Deklaration von
   Skalartypen ist im Abschnitt über die
   <a href="language.types.declarations.php" class="link">Deklaration des Typs</a>
   zu finden.
  </p>
 </div>

 <div class="sect2" id="migration70.new-features.return-type-declarations">
  <h3 class="title">Deklaration des Rückgabetyps</h3>

  <p class="para">
   PHP 7 unterstützt die
   <a href="language.types.declarations.php" class="link">Deklaration des Rückgabetyps</a>.
   Ähnlich wie bei der
   <a href="language.types.declarations.php" class="link">Deklaration des Parameter-Typs</a>
   gibt die Deklaration des Rückgabetyps den Typ des Wertes an, der von einer
   Funktion zurückgegeben wird. Für die Deklaration des Rückgabetyps stehen
   dieselben <a href="language.types.declarations.php" class="link">Typen</a> zur
   Verfügung wie für die Deklaration des Parameter-Typs.
  </p>

  <div class="informalexample">
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">function </span><span style="color: #0000BB">arraysSum</span><span style="color: #007700">(array ...</span><span style="color: #0000BB">$arrays</span><span style="color: #007700">): array<br />{<br />    return </span><span style="color: #0000BB">array_map</span><span style="color: #007700">(function(array </span><span style="color: #0000BB">$array</span><span style="color: #007700">): </span><span style="color: #0000BB">int </span><span style="color: #007700">{<br />        return </span><span style="color: #0000BB">array_sum</span><span style="color: #007700">(</span><span style="color: #0000BB">$array</span><span style="color: #007700">);<br />    }, </span><span style="color: #0000BB">$arrays</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">arraysSum</span><span style="color: #007700">([</span><span style="color: #0000BB">1</span><span style="color: #007700">,</span><span style="color: #0000BB">2</span><span style="color: #007700">,</span><span style="color: #0000BB">3</span><span style="color: #007700">], [</span><span style="color: #0000BB">4</span><span style="color: #007700">,</span><span style="color: #0000BB">5</span><span style="color: #007700">,</span><span style="color: #0000BB">6</span><span style="color: #007700">], [</span><span style="color: #0000BB">7</span><span style="color: #007700">,</span><span style="color: #0000BB">8</span><span style="color: #007700">,</span><span style="color: #0000BB">9</span><span style="color: #007700">]));</span></span></code></div>
   </div>

   <p class="para">Das oben gezeigte Beispiel erzeugt folgende Ausgabe:</p>
   <div class="example-contents screen">
<div class="cdata"><pre>
Array
(
    [0] =&gt; 6
    [1] =&gt; 15
    [2] =&gt; 24
)
</pre></div>
   </div>
  </div>

  <p class="para">
   Eine vollständige Dokumentation und Beispiele für die Deklaration des
   Rückgabetyps ist im Abschnitt über die
   <a href="language.types.declarations.php" class="link">Deklaration des Rückgabetyps</a>
   zu finden.
  </p>
 </div>

 <div class="sect2" id="migration70.new-features.null-coalesce-op">
  <h3 class="title">Null-Koaleszenz-Operator</h3>

  <p class="para">
   Der null-Koaleszenz-Operator (etwa: Operator für die Kombination mit null)
   <code class="literal">??</code> wurde als syntaktische Vereinfachung hinzugefügt für
   den häufigen Fall, dass ein ternärer Operator in Verbindung mit
   <span class="function"><a href="function.isset.php" class="function">isset()</a></span> verwendet wird. Er gibt seinen ersten Operanden
   zurück, wenn er existiert und nicht <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> ist; andernfalls gibt er seinen
   zweiten Operanden zurück.
  </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">// Gibt den Wert von $_GET['user'] zurück, falls er existiert,<br />// und andernfalls 'nobody'.<br /></span><span style="color: #0000BB">$username </span><span style="color: #007700">= </span><span style="color: #0000BB">$_GET</span><span style="color: #007700">[</span><span style="color: #DD0000">'user'</span><span style="color: #007700">] ?? </span><span style="color: #DD0000">'nobody'</span><span style="color: #007700">;<br /></span><span style="color: #FF8000">// Dies ist gleichbedeutend mit:<br /></span><span style="color: #0000BB">$username </span><span style="color: #007700">= isset(</span><span style="color: #0000BB">$_GET</span><span style="color: #007700">[</span><span style="color: #DD0000">'user'</span><span style="color: #007700">]) ? </span><span style="color: #0000BB">$_GET</span><span style="color: #007700">[</span><span style="color: #DD0000">'user'</span><span style="color: #007700">] : </span><span style="color: #DD0000">'nobody'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Dieser Operator kann verkettet werden. Das Beispiel gibt den<br />// ersten definierten Wert aus $_GET['user'], $_POST['user'] und<br />// 'nobody' zurück.<br /></span><span style="color: #0000BB">$username </span><span style="color: #007700">= </span><span style="color: #0000BB">$_GET</span><span style="color: #007700">[</span><span style="color: #DD0000">'user'</span><span style="color: #007700">] ?? </span><span style="color: #0000BB">$_POST</span><span style="color: #007700">[</span><span style="color: #DD0000">'user'</span><span style="color: #007700">] ?? </span><span style="color: #DD0000">'nobody'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

  </div>

  
 </div>

 <div class="sect2" id="migration70.new-features.spaceship-op">
  <h3 class="title">Raumschiff-Operator (Spaceship)</h3>
  <p class="para">
   Der Raumschiff-Operator wird für den Vergleich zweier Ausdrücke verwendet.
   Er gibt -1, 0  oder 1 zurück, wenn <var class="varname">$a</var> kleiner, gleich
   oder größer ist als <var class="varname">$b</var>. Vergleiche werden gemäß den
   üblichen Regeln für
   <a href="types.comparisons.php" class="link">Typenvergleiche in PHP</a>
   durchgeführt.
  </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">// Ganzzahlen<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">1 </span><span style="color: #007700">&lt;=&gt; </span><span style="color: #0000BB">1</span><span style="color: #007700">; </span><span style="color: #FF8000">// 0<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">1 </span><span style="color: #007700">&lt;=&gt; </span><span style="color: #0000BB">2</span><span style="color: #007700">; </span><span style="color: #FF8000">// -1<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">2 </span><span style="color: #007700">&lt;=&gt; </span><span style="color: #0000BB">1</span><span style="color: #007700">; </span><span style="color: #FF8000">// 1<br /><br />// Gleitkommazahlen<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">1.5 </span><span style="color: #007700">&lt;=&gt; </span><span style="color: #0000BB">1.5</span><span style="color: #007700">; </span><span style="color: #FF8000">// 0<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">1.5 </span><span style="color: #007700">&lt;=&gt; </span><span style="color: #0000BB">2.5</span><span style="color: #007700">; </span><span style="color: #FF8000">// -1<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">2.5 </span><span style="color: #007700">&lt;=&gt; </span><span style="color: #0000BB">1.5</span><span style="color: #007700">; </span><span style="color: #FF8000">// 1<br /><br />// Zeichenketten<br /></span><span style="color: #007700">echo </span><span style="color: #DD0000">"a" </span><span style="color: #007700">&lt;=&gt; </span><span style="color: #DD0000">"a"</span><span style="color: #007700">; </span><span style="color: #FF8000">// 0<br /></span><span style="color: #007700">echo </span><span style="color: #DD0000">"a" </span><span style="color: #007700">&lt;=&gt; </span><span style="color: #DD0000">"b"</span><span style="color: #007700">; </span><span style="color: #FF8000">// -1<br /></span><span style="color: #007700">echo </span><span style="color: #DD0000">"b" </span><span style="color: #007700">&lt;=&gt; </span><span style="color: #DD0000">"a"</span><span style="color: #007700">; </span><span style="color: #FF8000">// 1<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

  </div>

  
 </div>

 <div class="sect2" id="migration70.new-features.define-array">
  <h3 class="title">Definieren von Array-Konstanten mit <span class="function"><a href="function.define.php" class="function">define()</a></span></h3>

  <p class="para">
   Es ist nun möglich, <span class="type"><a href="language.types.array.php" class="type Array">Array</a></span>-Konstanten mit
   <span class="function"><a href="function.define.php" class="function">define()</a></span> zu definieren. Bis zu PHP 5.6 konnten
   Array-Konstanten nur mit <a href="language.constants.syntax.php" class="link"><code class="literal">const</code></a> definiert werden.
  </p>

  <div class="informalexample">
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />define</span><span style="color: #007700">(</span><span style="color: #DD0000">'ANIMALS'</span><span style="color: #007700">, [<br />    </span><span style="color: #DD0000">'dog'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'cat'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'bird'<br /></span><span style="color: #007700">]);<br /><br />echo </span><span style="color: #0000BB">ANIMALS</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">]; </span><span style="color: #FF8000">// gibt "cat" aus<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

  </div>
 </div>

 <div class="sect2" id="migration70.new-features.anonymous-classes">
  <h3 class="title">Anonyme Klassen</h3>

  <p class="para">
   Mit <code class="literal">new class</code> wurde die Unterstützung für anonyme Klassen
   hinzugefügt. Dies kann anstelle von vollständigen Klassendefinitionen
   verwendet werden für Objekte, die nur einmal benötigt werden:
  </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">interface </span><span style="color: #0000BB">Logger </span><span style="color: #007700">{<br />    public function </span><span style="color: #0000BB">log</span><span style="color: #007700">(</span><span style="color: #0000BB">string $msg</span><span style="color: #007700">);<br />}<br /><br />class </span><span style="color: #0000BB">Application </span><span style="color: #007700">{<br />    private </span><span style="color: #0000BB">$logger</span><span style="color: #007700">;<br /><br />    public function </span><span style="color: #0000BB">getLogger</span><span style="color: #007700">(): </span><span style="color: #0000BB">Logger </span><span style="color: #007700">{<br />         return </span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">logger</span><span style="color: #007700">;<br />    }<br /><br />    public function </span><span style="color: #0000BB">setLogger</span><span style="color: #007700">(</span><span style="color: #0000BB">Logger $logger</span><span style="color: #007700">) {<br />         </span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">logger </span><span style="color: #007700">= </span><span style="color: #0000BB">$logger</span><span style="color: #007700">;<br />    }<br />}<br /><br /></span><span style="color: #0000BB">$app </span><span style="color: #007700">= new </span><span style="color: #0000BB">Application</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$app</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setLogger</span><span style="color: #007700">(new class implements </span><span style="color: #0000BB">Logger </span><span style="color: #007700">{<br />    public function </span><span style="color: #0000BB">log</span><span style="color: #007700">(</span><span style="color: #0000BB">string $msg</span><span style="color: #007700">) {<br />        echo </span><span style="color: #0000BB">$msg</span><span style="color: #007700">;<br />    }<br />});<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$app</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getLogger</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <p class="para">Das oben gezeigte Beispiel erzeugt folgende Ausgabe:</p>
   <div class="example-contents screen">
<div class="cdata"><pre>
object(class@anonymous)#2 (0) {
}
</pre></div>
   </div>
  </div>

  <p class="para">
   Die vollständige Dokumentation befindet sich im Abschnitt
   <a href="language.oop5.anonymous.php" class="link">Anonyme Klassen</a>.
  </p>
 </div>

 <div class="sect2" id="migration70.new-features.unicode-codepoint-escape-syntax">
  <h3 class="title">Syntax für die Maskierung von Unicode-Codepunkten</h3>

  <p class="para">
   Diese Syntax nimmt einen Unicode-Codepunkt in hexadezimaler Form und gibt
   diesen Codepunkt in UTF-8 in eine Zeichenkette mit doppelten
   Anführungszeichen oder einen Heredoc aus. Jeder gültige Codepunkt wird
   akzeptiert, wobei führende Nullen optional sind.
  </p>

  <div class="informalexample">
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">echo </span><span style="color: #DD0000">"\u{aa}"</span><span style="color: #007700">, </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />echo </span><span style="color: #DD0000">"\u{0000aa}"</span><span style="color: #007700">, </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /><br />echo </span><span style="color: #DD0000">"\u{9999}"</span><span style="color: #007700">, </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /><br />echo &lt;&lt;&lt;EOT<br /></span><span style="color: #DD0000">\u{01f418}<br /></span><span style="color: #007700">EOT;<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <p class="para">Das oben gezeigte Beispiel erzeugt folgende Ausgabe:</p>
   <div class="example-contents screen">
<div class="cdata"><pre>
ª
ª (wie zuvor, jedoch mit führenden Nullen)
香
</pre></div>
   </div>
  </div>
 </div>

 <div class="sect2" id="migration70.new-features.closure-call-method">
  <h3 class="title"><span class="methodname"><a href="closure.call.php" class="methodname">Closure::call()</a></span></h3>

  <p class="para">
   Die Methode <span class="methodname"><a href="closure.call.php" class="methodname">Closure::call()</a></span> ist ein
   leistungsfähigerer und kürzerer Weg, um den Gültigkeitsbereich eines
   Objekts vorübergehend an eine Closure zu binden und diese aufzurufen.
  </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 </span><span style="color: #0000BB">A </span><span style="color: #007700">{private </span><span style="color: #0000BB">$x </span><span style="color: #007700">= </span><span style="color: #0000BB">1</span><span style="color: #007700">;}<br /><br /></span><span style="color: #FF8000">// Code vor PHP 7<br /></span><span style="color: #0000BB">$getX </span><span style="color: #007700">= function() {return </span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">x</span><span style="color: #007700">;};<br /></span><span style="color: #0000BB">$getXCB </span><span style="color: #007700">= </span><span style="color: #0000BB">$getX</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">bindTo</span><span style="color: #007700">(new </span><span style="color: #0000BB">A</span><span style="color: #007700">, </span><span style="color: #DD0000">'A'</span><span style="color: #007700">); </span><span style="color: #FF8000">// zwischengeschaltete Closure<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">$getXCB</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">// Code in PHP 7+<br /></span><span style="color: #0000BB">$getX </span><span style="color: #007700">= function() {return </span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">x</span><span style="color: #007700">;};<br />echo </span><span style="color: #0000BB">$getX</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">call</span><span style="color: #007700">(new </span><span style="color: #0000BB">A</span><span style="color: #007700">);</span></span></code></div>
   </div>

   <p class="para">Das oben gezeigte Beispiel erzeugt folgende Ausgabe:</p>
   <div class="example-contents screen">
<div class="cdata"><pre>
1
1
</pre></div>
   </div>
  </div>
 </div>
 <div class="sect2" id="migration70.new-features.filtered-unserialize">
  <h3 class="title">Gefiltertes <span class="function"><a href="function.unserialize.php" class="function">unserialize()</a></span></h3>

  <p class="para">
   Dieser Mechanismus soll zusätzliche Sicherheit beim Deserialisieren von
   Objekten aus nicht vertrauenswürdigen Daten bieten. Durch die Definition
   einer Whitelist für Klassen, die deserialisiert werden dürfen, können
   Angriffe durch Code-Injection verhindert werden.
  </p>

  <div class="informalexample">
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">// wandelt alle Objekte in __PHP_Incomplete_Class-Objekte um<br /></span><span style="color: #0000BB">$data </span><span style="color: #007700">= </span><span style="color: #0000BB">unserialize</span><span style="color: #007700">(</span><span style="color: #0000BB">$foo</span><span style="color: #007700">, [</span><span style="color: #DD0000">"allowed_classes" </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">false</span><span style="color: #007700">]);<br /><br /></span><span style="color: #FF8000">// wandelt mit Ausnahme von MyClass und MyClass2 alle Objekte in __PHP_Incomplete_Class-Objekte um<br /></span><span style="color: #0000BB">$data </span><span style="color: #007700">= </span><span style="color: #0000BB">unserialize</span><span style="color: #007700">(</span><span style="color: #0000BB">$foo</span><span style="color: #007700">, [</span><span style="color: #DD0000">"allowed_classes" </span><span style="color: #007700">=&gt; [</span><span style="color: #DD0000">"MyClass"</span><span style="color: #007700">, </span><span style="color: #DD0000">"MyClass2"</span><span style="color: #007700">]]);<br /><br /></span><span style="color: #FF8000">// In der Voreinstellung (entspricht dem Weglassen des zweiten Parameters) werden alle Klassen akzeptiert<br /></span><span style="color: #0000BB">$data </span><span style="color: #007700">= </span><span style="color: #0000BB">unserialize</span><span style="color: #007700">(</span><span style="color: #0000BB">$foo</span><span style="color: #007700">, [</span><span style="color: #DD0000">"allowed_classes" </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">true</span><span style="color: #007700">]);</span></span></code></div>
   </div>

  </div>
 </div>

 <div class="sect2" id="migration70.new-features.intlchar">
  <h3 class="title"><span class="classname"><a href="class.intlchar.php" class="classname">IntlChar</a></span></h3>

  <p class="para">
   Die neue Klasse <span class="classname"><a href="class.intlchar.php" class="classname">IntlChar</a></span> wurde hinzugefügt, um
   zusätzliche Funktionalitäten von ICU zu nutzen. Die Klasse selbst definiert
   eine Reihe von statischen Methoden und Konstanten, die zur Bearbeitung von
   Unicode-Zeichen verwendet werden können.
  </p>

  <div class="informalexample">
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br />printf</span><span style="color: #007700">(</span><span style="color: #DD0000">'%x'</span><span style="color: #007700">, </span><span style="color: #0000BB">IntlChar</span><span style="color: #007700">::</span><span style="color: #0000BB">CODEPOINT_MAX</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">IntlChar</span><span style="color: #007700">::</span><span style="color: #0000BB">charName</span><span style="color: #007700">(</span><span style="color: #DD0000">'@'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">IntlChar</span><span style="color: #007700">::</span><span style="color: #0000BB">ispunct</span><span style="color: #007700">(</span><span style="color: #DD0000">'!'</span><span style="color: #007700">));</span></span></code></div>
   </div>

   <p class="para">Das oben gezeigte Beispiel erzeugt folgende Ausgabe:</p>
   <div class="example-contents screen">
<div class="cdata"><pre>
10ffff
COMMERCIAL AT
bool(true)
</pre></div>
   </div>
  </div>

  <p class="para">
   Um diese Klasse verwenden zu können, muss die Erweiterung
   <a href="book.intl.php" class="link">Intl</a> installiert sein.
  </p>
 </div>

 <div class="sect2" id="migration70.new-features.expectations">
  <h3 class="title">Expectations (Annahmen)</h3>

  <p class="para">
   Die Expectations sind eine abwärtskompatible Weiterentwicklung der alten
   Funktion <span class="function"><a href="function.assert.php" class="function">assert()</a></span>. Sie ermöglichen Assertions ohne
   Leistungsverluste im Produktionscode und bieten die Möglichkeit,
   benutzerdefinierte Exceptions auszulösen, wenn eine Assertion fehlschlägt.
  </p>

  <p class="para">
   Während die alte API aus Kompatibilitätsgründen beibehalten wird, ist
   <span class="function"><a href="function.assert.php" class="function">assert()</a></span> nun ein Sprachkonstrukt, das es ermöglicht,
   dass der erste Parameter ein Ausdruck sein kann und nicht nur ein
   auszuwertender <span class="type"><a href="language.types.string.php" class="type string">string</a></span>-Wert oder ein zu testender
   <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span>)-Wert.
  </p>

  <div class="informalexample">
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />ini_set</span><span style="color: #007700">(</span><span style="color: #DD0000">'assert.exception'</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /><br />class </span><span style="color: #0000BB">CustomError </span><span style="color: #007700">extends </span><span style="color: #0000BB">AssertionError </span><span style="color: #007700">{}<br /><br /></span><span style="color: #0000BB">assert</span><span style="color: #007700">(</span><span style="color: #0000BB">false</span><span style="color: #007700">, new </span><span style="color: #0000BB">CustomError</span><span style="color: #007700">(</span><span style="color: #DD0000">'Irgendeine Fehlermeldung'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <p class="para">Das oben gezeigte Beispiel erzeugt folgende Ausgabe:</p>
   <div class="example-contents screen">
<div class="cdata"><pre>
Fatal error: Uncaught CustomError: Irgendeine Fehlermeldung
</pre></div>
   </div>
  </div>

  <p class="para">
   Alle Details zu diesem Feature, einschließlich der Konfiguration sowohl in
   Entwicklungs- als auch in Produktionsumgebungen, befinden sich auf der
   Handbuchseite des Sprachkonstrukts <span class="function"><a href="function.assert.php" class="function">assert()</a></span>.
  </p>
 </div>

 <div class="sect2" id="migration70.new-features.group-use-declarations">
  <h3 class="title">Zusammengefasste <code class="literal">use</code>-Deklarationen</h3>

  <p class="para">
   Klassen, Funktionen und Konstanten, die aus demselben <a href="language.namespaces.definition.php" class="link"><code class="literal">namespace</code></a>
   importiert werden, können nun in einer einzigen <a href="language.namespaces.importing.php" class="link"><code class="literal">use</code></a>-Anweisung
   zusammengefasst werden.
  </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">// Code vor PHP 7<br /></span><span style="color: #007700">use </span><span style="color: #0000BB">some\namespace\ClassA</span><span style="color: #007700">;<br />use </span><span style="color: #0000BB">some\namespace\ClassB</span><span style="color: #007700">;<br />use </span><span style="color: #0000BB">some\namespace\ClassC </span><span style="color: #007700">as </span><span style="color: #0000BB">C</span><span style="color: #007700">;<br /><br />use function </span><span style="color: #0000BB">some\namespace\fn_a</span><span style="color: #007700">;<br />use function </span><span style="color: #0000BB">some\namespace\fn_b</span><span style="color: #007700">;<br />use function </span><span style="color: #0000BB">some\namespace\fn_c</span><span style="color: #007700">;<br /><br />use const </span><span style="color: #0000BB">some\namespace\ConstA</span><span style="color: #007700">;<br />use const </span><span style="color: #0000BB">some\namespace\ConstB</span><span style="color: #007700">;<br />use const </span><span style="color: #0000BB">some\namespace\ConstC</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Code in PHP 7+<br /></span><span style="color: #007700">use </span><span style="color: #0000BB">some\namespace</span><span style="color: #007700">\{</span><span style="color: #0000BB">ClassA</span><span style="color: #007700">, </span><span style="color: #0000BB">ClassB</span><span style="color: #007700">, </span><span style="color: #0000BB">ClassC </span><span style="color: #007700">as </span><span style="color: #0000BB">C</span><span style="color: #007700">};<br />use function </span><span style="color: #0000BB">some\namespace</span><span style="color: #007700">\{</span><span style="color: #0000BB">fn_a</span><span style="color: #007700">, </span><span style="color: #0000BB">fn_b</span><span style="color: #007700">, </span><span style="color: #0000BB">fn_c</span><span style="color: #007700">};<br />use const </span><span style="color: #0000BB">some\namespace</span><span style="color: #007700">\{</span><span style="color: #0000BB">ConstA</span><span style="color: #007700">, </span><span style="color: #0000BB">ConstB</span><span style="color: #007700">, </span><span style="color: #0000BB">ConstC</span><span style="color: #007700">};<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

  </div>
 </div>

 <div class="sect2" id="migration70.new-features.generator-return-expressions">
  <h3 class="title">Generatoren können Werte zurückgeben</h3>

  <p class="para">
   Dieses Feature baut auf der Generator-Funktionalität auf, die in PHP 5.5
   eingeführt wurde. Sie ermöglicht es, eine <code class="literal">return</code>-Anweisung
   innerhalb eines Generators zu verwenden, damit der Wert eines Ausdrucks
   zurückgegeben werden kann (eine Rückgabe per Referenz ist nicht erlaubt).
   Dieser Wert kann mit der neuen Methode
   <code class="literal">Generator::getReturn()</code> abgerufen werden, die erst
   verwendet werden darf, nachdem der Generator die Ausgabe von Werten
   abgeschlossen hat.
  </p>

  <div class="informalexample">
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br />$gen </span><span style="color: #007700">= (function() {<br />    yield </span><span style="color: #0000BB">1</span><span style="color: #007700">;<br />    yield </span><span style="color: #0000BB">2</span><span style="color: #007700">;<br /><br />    return </span><span style="color: #0000BB">3</span><span style="color: #007700">;<br />})();<br /><br />foreach (</span><span style="color: #0000BB">$gen </span><span style="color: #007700">as </span><span style="color: #0000BB">$val</span><span style="color: #007700">) {<br />    echo </span><span style="color: #0000BB">$val</span><span style="color: #007700">, </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />}<br /><br />echo </span><span style="color: #0000BB">$gen</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getReturn</span><span style="color: #007700">(), </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;</span></span></code></div>
   </div>

   <p class="para">Das oben gezeigte Beispiel erzeugt folgende Ausgabe:</p>
   <div class="example-contents screen">
<div class="cdata"><pre>
1
2
3
</pre></div>
   </div>
  </div>

  <p class="para">
   Die Möglichkeit, den Endwert eines Generators explizit zurückzugeben, ist
   sehr nützlich. Dadurch kann der Client-Code, der den Generator ausführt,
   den letzten vom Generator zurückgegebenen Wert (das Ergebnis einer
   Berechnung durch eine Art Co-Routine) als Sonderfall behandeln. Dies ist
   viel einfacher, als einen clientseitigen Code zu schreiben, der zunächst
   prüft, ob der zurückgegebene Wert der Letzte ist, und ihn dann
   gegebenenfalls als speziellen Wert behandelt.
  </p>
 </div>
 <div class="sect2" id="migration70.new-features.generator-delegation">
  <h3 class="title">Delegierung durch Generatoren</h3>

  <p class="para">
   Generatoren können nun automatisch an einen anderen Generator, ein
   <span class="classname"><a href="class.traversable.php" class="classname">Traversable</a></span>-Objekt oder ein <span class="type"><a href="language.types.array.php" class="type Array">Array</a></span>
   delegieren, ohne dass Boilerplate (redundanter Code) in den äußersten
   Generator geschrieben werden muss. Dies wird durch die Verwendung des
   Konstrukts <a href="language.generators.syntax.php#control-structures.yield.from" class="link"><code class="literal">yield from</code></a> erreicht.
  </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 </span><span style="color: #0000BB">gen</span><span style="color: #007700">()<br />{<br />    yield </span><span style="color: #0000BB">1</span><span style="color: #007700">;<br />    yield </span><span style="color: #0000BB">2</span><span style="color: #007700">;<br />    yield from </span><span style="color: #0000BB">gen2</span><span style="color: #007700">();<br />}<br /><br />function </span><span style="color: #0000BB">gen2</span><span style="color: #007700">()<br />{<br />    yield </span><span style="color: #0000BB">3</span><span style="color: #007700">;<br />    yield </span><span style="color: #0000BB">4</span><span style="color: #007700">;<br />}<br /><br />foreach (</span><span style="color: #0000BB">gen</span><span style="color: #007700">() as </span><span style="color: #0000BB">$val</span><span style="color: #007700">)<br />{<br />    echo </span><span style="color: #0000BB">$val</span><span style="color: #007700">, </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <p class="para">Das oben gezeigte Beispiel erzeugt folgende Ausgabe:</p>
   <div class="example-contents screen">
<div class="cdata"><pre>
1
2
3
4
</pre></div>
   </div>
  </div>
 </div>

 <div class="sect2" id="migration70.new-features.intdiv">
  <h3 class="title">Ganzzahl-Division mit <span class="function"><a href="function.intdiv.php" class="function">intdiv()</a></span></h3>

  <p class="para">
   Die neue Funktion <span class="function"><a href="function.intdiv.php" class="function">intdiv()</a></span> führt eine Ganzzahl-Division
   ihrer Operanden durch und gibt das Ergebnis zurück.
  </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">intdiv</span><span style="color: #007700">(</span><span style="color: #0000BB">10</span><span style="color: #007700">, </span><span style="color: #0000BB">3</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <p class="para">Das oben gezeigte Beispiel erzeugt folgende Ausgabe:</p>
   <div class="example-contents screen">
<div class="cdata"><pre>
int(3)
</pre></div>
   </div>
  </div>
 </div>

 <div class="sect2" id="migration70.new-features.session-options">
  <h3 class="title">Optionen für Session</h3>

  <p class="para">
   Die Funktion <span class="function"><a href="function.session-start.php" class="function">session_start()</a></span> akzeptiert nun ein
   <span class="type"><a href="language.types.array.php" class="type Array">Array</a></span> von Optionen. Diese überschreiben die
   <a href="session.configuration.php" class="link">Session-Konfigurationsanweisungen</a>,
   die normalerweise in der php.ini gesetzt werden.
  </p>

  <p class="para">
   Diese Optionen unterstützen nun auch
   <a href="session.configuration.php#ini.session.lazy-write" class="link">session.lazy_write</a>. Diese
   Option ist standardmäßig aktiviert und bewirkt, dass PHP eine Session-Datei
   nur dann überschreibt, wenn sich die Session-Daten geändert haben. Außerdem
   wurde die Option <code class="literal">read_and_close</code> hinzugefügt. Sie kann
   nur an <span class="function"><a href="function.session-start.php" class="function">session_start()</a></span> übergeben werden und gibt an,
   dass die Session-Daten gelesen werden sollen und die Session dann sofort
   unverändert geschlossen werden soll.
  </p>

  <p class="para">
   Um zum Beispiel
   <a href="session.configuration.php#ini.session.cache-limiter" class="link">session.cache_limiter</a> auf
   <code class="literal">private</code> zu setzen und die Session nach dem Lesen sofort
   zu schließen, kann Folgendes verwendet werden:
  </p>

  <div class="informalexample">
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />session_start</span><span style="color: #007700">([<br />    </span><span style="color: #DD0000">'cache_limiter' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'private'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'read_and_close' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">true</span><span style="color: #007700">,<br />]);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

  </div>
 </div>

 <div class="sect2" id="migration70.new-features.preg-repace-callback-array-function">
  <h3 class="title"><span class="function"><a href="function.preg-replace-callback-array.php" class="function">preg_replace_callback_array()</a></span></h3>

  <p class="para">
   Wenn die Funktion <span class="function"><a href="function.preg-replace-callback.php" class="function">preg_replace_callback()</a></span> verwendet
   werden müsste, kann stattdessen mit der neuen Funktion
   <span class="function"><a href="function.preg-replace-callback-array.php" class="function">preg_replace_callback_array()</a></span> saubererer Code
   geschrieben werden. Vor PHP 7 musste für jeden regulären Ausdruck ein
   Callback ausgeführt werden, was dazu führte, dass die Callback-Funktion
   voller Verzweigungen sein musste.
  </p>

  <p class="para">
   Nun können Callbacks für jeden regulären Ausdruck registriert werden, indem
   ein assoziatives Array verwendet wird, bei dem die regulären Ausdrücke
   die Schlüssel sind, und die Callback-Funktionen deren Werte.
  </p>
 </div>

 <div class="sect2" id="migration70.new-features.csprng-functions">
  <h3 class="title">CSPRNG-Funktionen</h3>

  <p class="para">
   Zwei neue Funktionen wurden hinzugefügt, um plattformübergreifend
   kryptographisch sichere Ganzzahlen und Zeichenketten zu erzeugen:
   <span class="function"><a href="function.random-bytes.php" class="function">random_bytes()</a></span> und <span class="function"><a href="function.random-int.php" class="function">random_int()</a></span>.
  </p>
 </div>

 <div class="sect2" id="migration70.new-features.list-arrayaccess">
  <h3 class="title">
   <span class="function"><a href="function.list.php" class="function">list()</a></span> kann nun immer Objekte entpacken, die
   <span class="classname"><a href="class.arrayaccess.php" class="classname">ArrayAccess</a></span> implementieren
  </h3>

  <p class="para">
   Zuvor war nicht gewährleistet, dass <span class="function"><a href="function.list.php" class="function">list()</a></span> bei Objekten,
   die <span class="classname"><a href="class.arrayaccess.php" class="classname">ArrayAccess</a></span> implementieren, korrekt funktioniert.
   Dies wurde nun behoben.
  </p>
 </div>

 <div class="sect2" id="migration70.new-features.others">
  <h3 class="title">Andere Features</h3>
  <ul class="itemizedlist">
   <li class="listitem">
    <span class="simpara">
     Es wurde die Möglichkeit hinzugefügt, beim Klonen auf Klassenelemente
     zuzugreifen, z. B. <code class="literal">(clone $foo)-&gt;bar()</code>.
    </span>
   </li>
  </ul>
 </div>
</div><?php manual_footer($setup); ?>