<h2 class="title" style="margin:0px 0px;overflow:hidden;font-weight:500;color:#793862;clear:both;font-family:'Fira Sans', 'Source Sans Pro', Helvetica, Arial, sans-serif;background-color:#f2f2f2;">New features<a class="genanchor" href="http://php.net/manual/en/migration70.new-features.php#migration70.new-features" style="border-bottom-style:none;text-decoration:none;border-top-width:0px;border-right-width:0px;border-left-width:0px;" target="_blank"> ¶</a></h2> <div class="sect2" style="color:#333333;font-family:'Fira Sans', 'Source Sans Pro', Helvetica, Arial, sans-serif;font-size:16px;line-height:24px;background-color:#f2f2f2;"> <h3 class="title" style="margin:0px 0px;overflow:hidden;font-weight:500;color:#793862;clear:both;">Scalar type declarations<a class="genanchor" href="http://php.net/manual/en/migration70.new-features.php#migration70.new-features.scalar-type-declarations" style="border-bottom-style:none;text-decoration:none;border-top-width:0px;border-right-width:0px;border-left-width:0px;" target="_blank"> ¶</a></h3> <p class="para" style="margin:0px 0px;">Scalar <a target="_blank" href="http://php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration" class="link" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank">type declarations</a> come in two flavours: coercive (default) and strict. The following types for parameters can now be enforced (either coercively or strictly): strings (<span class="type"><a target="_blank" href="http://php.net/manual/en/language.types.string.php" class="type string" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank">string</a></span>), integers (<em>int</em>), floating-point numbers (<span class="type"><a target="_blank" href="http://php.net/manual/en/language.types.float.php" class="type float" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank">float</a></span>), and booleans (<em>bool</em>). They augment the other types introduced in PHP 5: class names, interfaces, <span class="type"><a target="_blank" href="http://php.net/manual/en/language.types.array.php" class="type array" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank">array</a></span> and <span class="type"><a target="_blank" href="http://php.net/manual/en/language.types.callable.php" class="type callable" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank">callable</a></span>.</p> <div class="informalexample" style="margin:0px;"> <div class="example-contents"> <div class="phpcode" style="background-color:#ffffff;"><code style="font-family:'Fira Mono', 'Source Code Pro', monospace;display:block;"><span style="color:#000000;"><span style="color:#0000bb;"><?php<br></span><span style="color:#ff8000;">// Coercive mode<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" style="margin:0px 0px;">The above example will output:</p> <div class="example-contents screen" style="background-color:#ffffff;"> <div class="cdata"><pre style="white-space:pre-wrap;margin-top:0px;margin-bottom:0px;">int(9) </pre></div></div></div> <p class="para" style="margin:0px 0px;">To enable strict mode, a single <a target="_blank" href="http://php.net/manual/en/control-structures.declare.php" class="link" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank"><em>declare</em></a> directive must be placed at the top of the file. This means that the strictness of typing for scalars is configured on a per-file basis. This directive not only affects the type declarations of parameters, but also a function's return type (see <a target="_blank" href="http://php.net/manual/en/functions.returning-values.php#functions.returning-values.type-declaration" class="link" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank">return type declarations</a>, built-in PHP functions, and functions from loaded extensions.</p> <p class="para" style="margin:0px 0px;">Full documentation and examples of scalar type declarations can be found in the <a target="_blank" href="http://php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration" class="link" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank">type declaration</a> reference.</p></div> <div class="sect2" style="color:#333333;font-family:'Fira Sans', 'Source Sans Pro', Helvetica, Arial, sans-serif;font-size:16px;line-height:24px;background-color:#f2f2f2;"> <h3 class="title" style="margin:0px 0px;overflow:hidden;font-weight:500;color:#793862;clear:both;">Return type declarations<a class="genanchor" href="http://php.net/manual/en/migration70.new-features.php#migration70.new-features.return-type-declarations" style="border-bottom-style:none;text-decoration:none;border-top-width:0px;border-right-width:0px;border-left-width:0px;" target="_blank"> ¶</a></h3> <p class="para" style="margin:0px 0px;">PHP 7 adds support for <a target="_blank" href="http://php.net/manual/en/functions.returning-values.php#functions.returning-values.type-declaration" class="link" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank">return type declarations</a>. Similarly to <a target="_blank" href="http://php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration" class="link" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank">argument type declarations</a>, return type declarations specify the type of the value that will be returned from a function. The same <a target="_blank" href="http://php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration.types" class="link" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank">types</a> are available for return type declarations as are available for argument type declarations.</p> <div class="informalexample" style="margin:0px;"> <div class="example-contents"> <div class="phpcode" style="background-color:#ffffff;"><code style="font-family:'Fira Mono', 'Source Code Pro', monospace;display:block;"><span style="color:#000000;"><span style="color:#0000bb;"><?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" style="margin:0px 0px;">The above example will output:</p> <div class="example-contents screen" style="background-color:#ffffff;"> <div class="cdata"><pre style="white-space:pre-wrap;margin-top:0px;margin-bottom:0px;">Array ( [0] => 6 [1] => 15 [2] => 24 ) </pre></div></div></div> <p class="para" style="margin:0px 0px;">Full documentation and examples of return type declarations can be found in the <a target="_blank" href="http://php.net/manual/en/functions.returning-values.php#functions.returning-values.type-declaration" class="link" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank">return type declarations</a>. reference.</p></div> <div class="sect2" style="color:#333333;font-family:'Fira Sans', 'Source Sans Pro', Helvetica, Arial, sans-serif;font-size:16px;line-height:24px;background-color:#f2f2f2;"> <h3 class="title" style="margin:0px 0px;overflow:hidden;font-weight:500;color:#793862;clear:both;">Null coalesce operator<a class="genanchor" href="http://php.net/manual/en/migration70.new-features.php#migration70.new-features.null-coalesce-op" style="border-bottom-style:none;text-decoration:none;border-top-width:0px;border-right-width:0px;border-left-width:0px;" target="_blank"> ¶</a></h3> <p class="para" style="margin:0px 0px;">The null coalesce operator (<em>??</em>) has been added as syntactic sugar for the common case of needing to use a ternary in conjunction with<span class="function"><a target="_blank" href="http://php.net/manual/en/function.isset.php" class="function" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank">isset()</a></span>. It returns its first operand if it exists and is not <span><code style="font-weight:700;font-family:'Fira Mono', 'Source Code Pro', monospace;">NULL</code></span>; otherwise it returns its second operand.</p> <div class="informalexample" style="margin:0px;"> <div class="example-contents"> <div class="phpcode" style="background-color:#ffffff;"><code style="font-family:'Fira Mono', 'Source Code Pro', monospace;display:block;"><span style="color:#000000;"><span style="color:#0000bb;"><?php<br></span><span style="color:#ff8000;">// Fetches the value of $_GET['user'] and returns 'nobody'<br>// if it does not exist.<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;">// This is equivalent to:<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;">// Coalesces can be chained: this will return the first<br>// defined value out of $_GET['user'], $_POST['user'], and<br>// '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:#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;">?></span></span></code></div></div></div></div> <div class="sect2" style="color:#333333;font-family:'Fira Sans', 'Source Sans Pro', Helvetica, Arial, sans-serif;font-size:16px;line-height:24px;background-color:#f2f2f2;"> <h3 class="title" style="margin:0px 0px;overflow:hidden;font-weight:500;color:#793862;clear:both;">Spaceship operator<a class="genanchor" href="http://php.net/manual/en/migration70.new-features.php#migration70.new-features.spaceship-op" style="border-bottom-style:none;text-decoration:none;border-top-width:0px;border-right-width:0px;border-left-width:0px;" target="_blank"> ¶</a></h3> <p class="para" style="margin:0px 0px;">The spaceship operator is used for comparing two expressions. It returns -1, 0 or 1 when <var class="varname" style="padding:2px 4px;white-space:nowrap;font-style:normal;font-size:14px;line-height:1.46;font-family:'Source Code Pro', monospace;background-color:#e6e6e6;"><var class="varname" style="padding:2px 4px;font-style:normal;line-height:1.46;">$a</var></var> is respectively less than, equal to, or greater than <var class="varname" style="padding:2px 4px;white-space:nowrap;font-style:normal;font-size:14px;line-height:1.46;font-family:'Source Code Pro', monospace;background-color:#e6e6e6;"><var class="varname" style="padding:2px 4px;font-style:normal;line-height:1.46;">$b</var></var>. Comparisons are performed according to PHP's usual <a target="_blank" href="http://php.net/manual/en/types.comparisons.php" class="link" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank">type comparison rules</a>.</p> <div class="informalexample" style="margin:0px;"> <div class="example-contents"> <div class="phpcode" style="background-color:#ffffff;"><code style="font-family:'Fira Mono', 'Source Code Pro', monospace;display:block;"><span style="color:#000000;"><span style="color:#0000bb;"><?php<br></span><span style="color:#ff8000;">// Integers<br></span><span style="color:#007700;">echo </span><span style="color:#0000bb;">1 </span><span style="color:#007700;"><=> </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;"><=> </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;"><=> </span><span style="color:#0000bb;">1</span><span style="color:#007700;">; </span><span style="color:#ff8000;">// 1<br><br>// Floats<br></span><span style="color:#007700;">echo </span><span style="color:#0000bb;">1.5 </span><span style="color:#007700;"><=> </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;"><=> </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;"><=> </span><span style="color:#0000bb;">1.5</span><span style="color:#007700;">; </span><span style="color:#ff8000;">// 1<br> <br>// Strings<br></span><span style="color:#007700;">echo </span><span style="color:#dd0000;">"a" </span><span style="color:#007700;"><=> </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;"><=> </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;"><=> </span><span style="color:#dd0000;">"a"</span><span style="color:#007700;">; </span><span style="color:#ff8000;">// 1<br></span><span style="color:#0000bb;">?></span></span></code></div></div></div></div> <div class="sect2" style="color:#333333;font-family:'Fira Sans', 'Source Sans Pro', Helvetica, Arial, sans-serif;font-size:16px;line-height:24px;background-color:#f2f2f2;"> <h3 class="title" style="margin:0px 0px;overflow:hidden;font-weight:500;color:#793862;clear:both;">Constant arrays using <span class="function"><a target="_blank" href="http://php.net/manual/en/function.define.php" class="function" style="border:0px;text-decoration:none;color:#336699;" target="_blank">define()</a></span><a class="genanchor" href="http://php.net/manual/en/migration70.new-features.php#migration70.new-features.define-array" style="border-bottom-style:none;text-decoration:none;border-top-width:0px;border-right-width:0px;border-left-width:0px;" target="_blank"> ¶</a></h3> <p class="para" style="margin:0px 0px;"><span class="type"><a target="_blank" href="http://php.net/manual/en/language.types.array.php" class="type Array" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank">Array</a></span> constants can now be defined with <span class="function"><a target="_blank" href="http://php.net/manual/en/function.define.php" class="function" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank">define()</a></span>. In PHP 5.6, they could only be defined with <a target="_blank" href="http://php.net/manual/en/language.constants.syntax.php" class="link" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank"><em>const</em></a>.</p> <div class="informalexample" style="margin:0px;"> <div class="example-contents"> <div class="phpcode" style="background-color:#ffffff;"><code style="font-family:'Fira Mono', 'Source Code Pro', monospace;display:block;"><span style="color:#000000;"><span style="color:#0000bb;"><?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;">// outputs "cat"<br></span><span style="color:#0000bb;">?></span></span></code></div></div></div></div> <div class="sect2" style="color:#333333;font-family:'Fira Sans', 'Source Sans Pro', Helvetica, Arial, sans-serif;font-size:16px;line-height:24px;background-color:#f2f2f2;"> <h3 class="title" style="margin:0px 0px;overflow:hidden;font-weight:500;color:#793862;clear:both;">Anonymous classes<a class="genanchor" href="http://php.net/manual/en/migration70.new-features.php#migration70.new-features.anonymous-classes" style="border-bottom-style:none;text-decoration:none;border-top-width:0px;border-right-width:0px;border-left-width:0px;" target="_blank"> ¶</a></h3> <p class="para" style="margin:0px 0px;">Support for anonymous classes has been added via <em>new class</em>. These can be used in place of full class definitions for throwaway objects:</p> <div class="informalexample" style="margin:0px;"> <div class="example-contents"> <div class="phpcode" style="background-color:#ffffff;"><code style="font-family:'Fira Mono', 'Source Code Pro', monospace;display:block;"><span style="color:#000000;"><span style="color:#0000bb;"><?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;">-></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;">-></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;">-></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;">-></span><span style="color:#0000bb;">getLogger</span><span style="color:#007700;">());<br></span><span style="color:#0000bb;">?></span></span></code></div></div> <p class="para" style="margin:0px 0px;">The above example will output:</p> <div class="example-contents screen" style="background-color:#ffffff;"> <div class="cdata"><pre style="white-space:pre-wrap;margin-top:0px;margin-bottom:0px;">object(class@anonymous)#2 (0) { } </pre></div></div></div> <p class="para" style="margin:0px 0px;">Full documentation can be found in the <a target="_blank" href="http://php.net/manual/en/language.oop5.anonymous.php" class="link" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank">anonymous class reference</a>.</p></div> <div class="sect2" style="color:#333333;font-family:'Fira Sans', 'Source Sans Pro', Helvetica, Arial, sans-serif;font-size:16px;line-height:24px;background-color:#f2f2f2;"> <h3 class="title" style="margin:0px 0px;overflow:hidden;font-weight:500;color:#793862;clear:both;">Unicode codepoint escape syntax<a class="genanchor" href="http://php.net/manual/en/migration70.new-features.php#migration70.new-features.unicode-codepoint-escape-syntax" style="border-bottom-style:none;text-decoration:none;border-top-width:0px;border-right-width:0px;border-left-width:0px;" target="_blank"> ¶</a></h3> <p class="para" style="margin:0px 0px;">This takes a Unicode codepoint in hexadecimal form, and outputs that codepoint in UTF-8 to a double-quoted string or a heredoc. Any valid codepoint is accepted, with leading 0's being optional.</p> <div class="informalexample" style="margin:0px;"> <div class="example-contents"> <div class="phpcode" style="background-color:#ffffff;"><code style="font-family:'Fira Mono', 'Source Code Pro', monospace;display:block;"><span style="color:#000000;">echo "\u{aa}";<br>echo "\u{0000aa}";<br>echo "\u{9999}";</span></code></div></div> <p class="para" style="margin:0px 0px;">The above example will output:</p> <div class="example-contents screen" style="background-color:#ffffff;"> <div class="cdata"><pre style="white-space:pre-wrap;margin-top:0px;margin-bottom:0px;">ª ª (same as before but with optional leading 0's) 香 </pre></div></div></div></div> <div class="sect2" style="color:#333333;font-family:'Fira Sans', 'Source Sans Pro', Helvetica, Arial, sans-serif;font-size:16px;line-height:24px;background-color:#f2f2f2;"> <h3 class="title" style="margin:0px 0px;overflow:hidden;font-weight:500;color:#793862;clear:both;"><span class="methodname"><a target="_blank" href="http://php.net/manual/en/closure.call.php" class="methodname" style="border:0px;text-decoration:none;color:#336699;" target="_blank">Closure::call()</a></span><a class="genanchor" href="http://php.net/manual/en/migration70.new-features.php#migration70.new-features.closure-call-method" style="border-bottom-style:none;text-decoration:none;border-top-width:0px;border-right-width:0px;border-left-width:0px;" target="_blank"> ¶</a></h3> <p class="para" style="margin:0px 0px;"><span class="methodname"><a target="_blank" href="http://php.net/manual/en/closure.call.php" class="methodname" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank">Closure::call()</a></span> is a more performant, shorthand way of temporarily binding an object scope to a closure and invoking it.</p> <div class="informalexample" style="margin:0px;"> <div class="example-contents"> <div class="phpcode" style="background-color:#ffffff;"><code style="font-family:'Fira Mono', 'Source Code Pro', monospace;display:block;"><span style="color:#000000;"><span style="color:#0000bb;"><?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;">// Pre PHP 7 code<br></span><span style="color:#0000bb;">$getXCB </span><span style="color:#007700;">= function() {return </span><span style="color:#0000bb;">$this</span><span style="color:#007700;">-></span><span style="color:#0000bb;">x</span><span style="color:#007700;">;};<br></span><span style="color:#0000bb;">$getX </span><span style="color:#007700;">= </span><span style="color:#0000bb;">$getXCB</span><span style="color:#007700;">-></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;">// intermediate closure<br></span><span style="color:#007700;">echo </span><span style="color:#0000bb;">$getX</span><span style="color:#007700;">();<br><br></span><span style="color:#ff8000;">// PHP 7+ code<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;">-></span><span style="color:#0000bb;">x</span><span style="color:#007700;">;};<br>echo </span><span style="color:#0000bb;">$getX</span><span style="color:#007700;">-></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" style="margin:0px 0px;">The above example will output:</p> <div class="example-contents screen" style="background-color:#ffffff;"> <div class="cdata"><pre style="white-space:pre-wrap;margin-top:0px;margin-bottom:0px;">1 1 </pre></div></div></div></div> <div class="sect2" style="color:#333333;font-family:'Fira Sans', 'Source Sans Pro', Helvetica, Arial, sans-serif;font-size:16px;line-height:24px;background-color:#f2f2f2;"> <h3 class="title" style="margin:0px 0px;overflow:hidden;font-weight:500;color:#793862;clear:both;">Filtered <span class="function"><a target="_blank" href="http://php.net/manual/en/function.unserialize.php" class="function" style="border:0px;text-decoration:none;color:#336699;" target="_blank">unserialize()</a></span><a class="genanchor" href="http://php.net/manual/en/migration70.new-features.php#migration70.new-features.filtered-unserialize" style="border-bottom-style:none;text-decoration:none;border-top-width:0px;border-right-width:0px;border-left-width:0px;" target="_blank"> ¶</a></h3> <p class="para" style="margin:0px 0px;">This feature seeks to provide better security when unserializing objects on untrusted data. It prevents possible code injections by enabling the developer to whitelist classes that can be unserialized.</p> <div class="informalexample" style="margin:0px;"> <div class="example-contents"> <div class="phpcode" style="background-color:#ffffff;"><code style="font-family:'Fira Mono', 'Source Code Pro', monospace;display:block;"><span style="color:#000000;"><span style="color:#0000bb;"><?php<br><br></span><span style="color:#ff8000;">// converts all objects into __PHP_Incomplete_Class object<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;">=> </span><span style="color:#0000bb;">false</span><span style="color:#007700;">]);<br><br></span><span style="color:#ff8000;">// converts all objects into __PHP_Incomplete_Class object except those of MyClass and MyClass2<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;">=> [</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;">// default behaviour (same as omitting the second argument) that accepts all classes<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;">=> </span><span style="color:#0000bb;">true</span><span style="color:#007700;">]);</span></span></code></div></div></div></div> <div class="sect2" style="color:#333333;font-family:'Fira Sans', 'Source Sans Pro', Helvetica, Arial, sans-serif;font-size:16px;line-height:24px;background-color:#f2f2f2;"> <h3 class="title" style="margin:0px 0px;overflow:hidden;font-weight:500;color:#793862;clear:both;"><a target="_blank" href="http://php.net/manual/en/class.intlchar.php" class="classname" style="border:0px;text-decoration:none;color:#336699;" target="_blank">IntlChar</a><a class="genanchor" href="http://php.net/manual/en/migration70.new-features.php#migration70.new-features.intlchar" style="border-bottom-style:none;text-decoration:none;border-top-width:0px;border-right-width:0px;border-left-width:0px;" target="_blank"> ¶</a></h3> <p class="para" style="margin:0px 0px;">The new <a target="_blank" href="http://php.net/manual/en/class.intlchar.php" class="classname" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank">IntlChar</a> class seeks to expose additional ICU functionality. The class itself defines a number of static methods and constants that can be used to manipulate unicode characters.</p> <div class="informalexample" style="margin:0px;"> <div class="example-contents"> <div class="phpcode" style="background-color:#ffffff;"><code style="font-family:'Fira Mono', 'Source Code Pro', monospace;display:block;"><span style="color:#000000;"><span style="color:#0000bb;"><?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" style="margin:0px 0px;">The above example will output:</p> <div class="example-contents screen" style="background-color:#ffffff;"> <div class="cdata"><pre style="white-space:pre-wrap;margin-top:0px;margin-bottom:0px;">10ffff COMMERCIAL AT bool(true) </pre></div></div></div> <p class="para" style="margin:0px 0px;">In order to use this class, the <a target="_blank" href="http://php.net/manual/en/book.intl.php" class="link" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank">Intl</a> extension must be installed.</p></div> <div class="sect2" style="color:#333333;font-family:'Fira Sans', 'Source Sans Pro', Helvetica, Arial, sans-serif;font-size:16px;line-height:24px;background-color:#f2f2f2;"> <h3 class="title" style="margin:0px 0px;overflow:hidden;font-weight:500;color:#793862;clear:both;">Expectations<a class="genanchor" href="http://php.net/manual/en/migration70.new-features.php#migration70.new-features.expectations" style="border-bottom-style:none;text-decoration:none;border-top-width:0px;border-right-width:0px;border-left-width:0px;" target="_blank"> ¶</a></h3> <p class="para" style="margin:0px 0px;"><a target="_blank" href="http://php.net/manual/en/function.assert.php#function.assert.expectations" class="link" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank">Expectations</a> are a backwards compatible enhancement to the older <span class="function"><a target="_blank" href="http://php.net/manual/en/function.assert.php" class="function" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank">assert()</a></span> function. They allow for zero-cost assertions in production code, and provide the ability to throw custom exceptions when the assertion fails.</p> <p class="para" style="margin:0px 0px;">While the old API continues to be maintained for compatibility, <span class="function"><a target="_blank" href="http://php.net/manual/en/function.assert.php" class="function" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank">assert()</a></span> is now a language construct, allowing the first parameter to be an expression rather than just a <span class="type"><a target="_blank" href="http://php.net/manual/en/language.types.string.php" class="type string" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank">string</a></span> to be evaluated or a <span class="type"><a target="_blank" href="http://php.net/manual/en/language.types.boolean.php" class="type boolean" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank">boolean</a></span> value to be tested.</p> <div class="informalexample" style="margin:0px;"> <div class="example-contents"> <div class="phpcode" style="background-color:#ffffff;"><code style="font-family:'Fira Mono', 'Source Code Pro', monospace;display:block;"><span style="color:#000000;"><span style="color:#0000bb;"><?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;">'Some error message'</span><span style="color:#007700;">));<br></span><span style="color:#0000bb;">?></span></span></code></div></div> <p class="para" style="margin:0px 0px;">The above example will output:</p> <div class="example-contents screen" style="background-color:#ffffff;"> <div class="cdata"><pre style="white-space:pre-wrap;margin-top:0px;margin-bottom:0px;">Fatal error: Uncaught CustomError: Some error message </pre></div></div></div> <p class="para" style="margin:0px 0px;">Full details on this feature, including how to configure it in both development and production environments, can be found in the<a target="_blank" href="http://php.net/manual/en/function.assert.php#function.assert.expectations" class="link" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank">expectations section</a> of the <span class="function"><a target="_blank" href="http://php.net/manual/en/function.assert.php" class="function" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank">assert()</a></span> reference.</p></div> <div class="sect2" style="color:#333333;font-family:'Fira Sans', 'Source Sans Pro', Helvetica, Arial, sans-serif;font-size:16px;line-height:24px;background-color:#f2f2f2;"> <h3 class="title" style="margin:0px 0px;overflow:hidden;font-weight:500;color:#793862;clear:both;">Group <em>use</em> declarations<a class="genanchor" href="http://php.net/manual/en/migration70.new-features.php#migration70.new-features.group-use-declarations" style="border-bottom-style:none;text-decoration:none;border-top-width:0px;border-right-width:0px;border-left-width:0px;" target="_blank"> ¶</a></h3> <p class="para" style="margin:0px 0px;">Classes, functions and constants being imported from the same <a target="_blank" href="http://php.net/manual/en/language.namespaces.definition.php" class="link" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank"><em>namespace</em></a> can now be grouped together in a single <a target="_blank" href="http://php.net/manual/en/language.namespaces.importing.php" class="link" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank"><em>use</em></a> statement.</p> <div class="informalexample" style="margin:0px;"> <div class="example-contents"> <div class="phpcode" style="background-color:#ffffff;"><code style="font-family:'Fira Mono', 'Source Code Pro', monospace;display:block;"><span style="color:#000000;"><span style="color:#0000bb;"><?php<br></span><span style="color:#ff8000;">// Pre PHP 7 code<br></span><span style="color:#007700;">use </span><span style="color:#0000bb;">some</span><span style="color:#007700;">\namespace\</span><span style="color:#0000bb;">ClassA</span><span style="color:#007700;">;<br>use </span><span style="color:#0000bb;">some</span><span style="color:#007700;">\namespace\</span><span style="color:#0000bb;">ClassB</span><span style="color:#007700;">;<br>use </span><span style="color:#0000bb;">some</span><span style="color:#007700;">\namespace\</span><span style="color:#0000bb;">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</span><span style="color:#007700;">\namespace\</span><span style="color:#0000bb;">fn_a</span><span style="color:#007700;">;<br>use function </span><span style="color:#0000bb;">some</span><span style="color:#007700;">\namespace\</span><span style="color:#0000bb;">fn_b</span><span style="color:#007700;">;<br>use function </span><span style="color:#0000bb;">some</span><span style="color:#007700;">\namespace\</span><span style="color:#0000bb;">fn_c</span><span style="color:#007700;">;<br><br>use const </span><span style="color:#0000bb;">some</span><span style="color:#007700;">\namespace\</span><span style="color:#0000bb;">ConstA</span><span style="color:#007700;">;<br>use const </span><span style="color:#0000bb;">some</span><span style="color:#007700;">\namespace\</span><span style="color:#0000bb;">ConstB</span><span style="color:#007700;">;<br>use const </span><span style="color:#0000bb;">some</span><span style="color:#007700;">\namespace\</span><span style="color:#0000bb;">ConstC</span><span style="color:#007700;">;<br><br></span><span style="color:#ff8000;">// PHP 7+ code<br></span><span style="color:#007700;">use </span><span style="color:#0000bb;">some</span><span style="color:#007700;">\namespace\{</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</span><span style="color:#007700;">\namespace\{</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</span><span style="color:#007700;">\namespace\{</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;">?></span></span></code></div></div></div></div> <div class="sect2" style="color:#333333;font-family:'Fira Sans', 'Source Sans Pro', Helvetica, Arial, sans-serif;font-size:16px;line-height:24px;background-color:#f2f2f2;"> <h3 class="title" style="margin:0px 0px;overflow:hidden;font-weight:500;color:#793862;clear:both;">Generator Return Expressions<a class="genanchor" href="http://php.net/manual/en/migration70.new-features.php#migration70.new-features.generator-return-expressions" style="border-bottom-style:none;text-decoration:none;border-top-width:0px;border-right-width:0px;border-left-width:0px;" target="_blank"> ¶</a></h3> <p class="para" style="margin:0px 0px;">This feature builds upon the generator functionality introduced into PHP 5.5. It enables for a <em>return</em> statement to be used within a generator to enable for a final expression to be returned (return by reference is not allowed). This value can be fetched using the new<em>Generator::getReturn()</em> method, which may only be used once the generator has finishing yielding values.</p> <div class="informalexample" style="margin:0px;"> <div class="example-contents"> <div class="phpcode" style="background-color:#ffffff;"><code style="font-family:'Fira Mono', 'Source Code Pro', monospace;display:block;"><span style="color:#000000;"><span style="color:#0000bb;"><?php<br><br>$gen </span><span style="color:#007700;">= (function() {<br> </span><span style="color:#0000bb;">yield 1</span><span style="color:#007700;">;<br> </span><span style="color:#0000bb;">yield 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;">-></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" style="margin:0px 0px;">The above example will output:</p> <div class="example-contents screen" style="background-color:#ffffff;"> <div class="cdata"><pre style="white-space:pre-wrap;margin-top:0px;margin-bottom:0px;">1 2 3 </pre></div></div></div> <p class="para" style="margin:0px 0px;">Being able to explicitly return a final value from a generator is a handy ability to have. This is because it enables for a final value to be returned by a generator (from perhaps some form of coroutine computation) that can be specifically handled by the client code executing the generator. This is far simpler than forcing the client code to firstly check whether the final value has been yielded, and then if so, to handle that value specifically.</p></div> <div class="sect2" style="color:#333333;font-family:'Fira Sans', 'Source Sans Pro', Helvetica, Arial, sans-serif;font-size:16px;line-height:24px;background-color:#f2f2f2;"> <h3 class="title" style="margin:0px 0px;overflow:hidden;font-weight:500;color:#793862;clear:both;">Generator delegation<a class="genanchor" href="http://php.net/manual/en/migration70.new-features.php#migration70.new-features.generator-delegation" style="border-bottom-style:none;text-decoration:none;border-top-width:0px;border-right-width:0px;border-left-width:0px;" target="_blank"> ¶</a></h3> <p class="para" style="margin:0px 0px;">Generators can now delegate to another generator, <a target="_blank" href="http://php.net/manual/en/class.traversable.php" class="classname" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank">Traversable</a> object or <span class="type"><a target="_blank" href="http://php.net/manual/en/language.types.array.php" class="type array" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank">array</a></span> automatically, without needing to write boilerplate in the outermost generator by using the <a target="_blank" href="http://php.net/manual/en/language.generators.syntax.php#control-structures.yield.from" class="link" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank"><em>yield from</em></a> construct.</p> <div class="informalexample" style="margin:0px;"> <div class="example-contents"> <div class="phpcode" style="background-color:#ffffff;"><code style="font-family:'Fira Mono', 'Source Code Pro', monospace;display:block;"><span style="color:#000000;"><span style="color:#0000bb;"><?php<br></span><span style="color:#007700;">function </span><span style="color:#0000bb;">gen</span><span style="color:#007700;">()<br>{<br> </span><span style="color:#0000bb;">yield 1</span><span style="color:#007700;">;<br> </span><span style="color:#0000bb;">yield 2</span><span style="color:#007700;">;<br> </span><span style="color:#0000bb;">yield from gen2</span><span style="color:#007700;">();<br>}<br><br>function </span><span style="color:#0000bb;">gen2</span><span style="color:#007700;">()<br>{<br> </span><span style="color:#0000bb;">yield 3</span><span style="color:#007700;">;<br> </span><span style="color:#0000bb;">yield 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;">?></span></span></code></div></div> <p class="para" style="margin:0px 0px;">The above example will output:</p> <div class="example-contents screen" style="background-color:#ffffff;"> <div class="cdata"><pre style="white-space:pre-wrap;margin-top:0px;margin-bottom:0px;">1 2 3 4 </pre></div></div></div></div> <div class="sect2" style="color:#333333;font-family:'Fira Sans', 'Source Sans Pro', Helvetica, Arial, sans-serif;font-size:16px;line-height:24px;background-color:#f2f2f2;"> <h3 class="title" style="margin:0px 0px;overflow:hidden;font-weight:500;color:#793862;clear:both;">Integer division with <span class="function"><a target="_blank" href="http://php.net/manual/en/function.intdiv.php" class="function" style="border:0px;text-decoration:none;color:#336699;" target="_blank">intdiv()</a></span><a class="genanchor" href="http://php.net/manual/en/migration70.new-features.php#migration70.new-features.intdiv" style="border-bottom-style:none;text-decoration:none;border-top-width:0px;border-right-width:0px;border-left-width:0px;" target="_blank"> ¶</a></h3> <p class="para" style="margin:0px 0px;">The new <span class="function"><a target="_blank" href="http://php.net/manual/en/function.intdiv.php" class="function" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank">intdiv()</a></span> function performs an integer division of its operands and returns it.</p> <div class="informalexample" style="margin:0px;"> <div class="example-contents"> <div class="phpcode" style="background-color:#ffffff;"><code style="font-family:'Fira Mono', 'Source Code Pro', monospace;display:block;"><span style="color:#000000;"><span style="color:#0000bb;"><?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;">?></span></span></code></div></div> <p class="para" style="margin:0px 0px;">The above example will output:</p> <div class="example-contents screen" style="background-color:#ffffff;"> <div class="cdata"><pre style="white-space:pre-wrap;margin-top:0px;margin-bottom:0px;">int(3) </pre></div></div></div></div> <div class="sect2" style="color:#333333;font-family:'Fira Sans', 'Source Sans Pro', Helvetica, Arial, sans-serif;font-size:16px;line-height:24px;background-color:#f2f2f2;"> <h3 class="title" style="margin:0px 0px;overflow:hidden;font-weight:500;color:#793862;clear:both;">Session options<a class="genanchor" href="http://php.net/manual/en/migration70.new-features.php#migration70.new-features.session-options" style="border-bottom-style:none;text-decoration:none;border-top-width:0px;border-right-width:0px;border-left-width:0px;" target="_blank"> ¶</a></h3> <p class="para" style="margin:0px 0px;"><span class="function"><a target="_blank" href="http://php.net/manual/en/function.session-start.php" class="function" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank">session_start()</a></span> now accepts an <span class="type"><a target="_blank" href="http://php.net/manual/en/language.types.array.php" class="type array" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank">array</a></span> of options that override the <a target="_blank" href="http://php.net/manual/en/session.configuration.php" class="link" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank">session configuration directives</a> normally set in php.ini.</p> <p class="para" style="margin:0px 0px;">These options have also been expanded to support <a target="_blank" href="http://php.net/manual/en/session.configuration.php#ini.session.lazy-write" class="link" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank">session.lazy_write</a>, which is on by default and causes PHP to only overwrite any session file if the session data has changed, and <em>read_and_close</em>, which is an option that can only be passed to <span class="function"><a target="_blank" href="http://php.net/manual/en/function.session-start.php" class="function" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank">session_start()</a></span> to indicate that the session data should be read and then the session should immediately be closed unchanged.</p> <p class="para" style="margin:0px 0px;">For example, to set <a target="_blank" href="http://php.net/manual/en/session.configuration.php#ini.session.cache-limiter" class="link" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank">session.cache_limiter</a> to <em>private</em> and immediately close the session after reading it:</p> <div class="informalexample" style="margin:0px;"> <div class="example-contents"> <div class="phpcode" style="background-color:#ffffff;"><code style="font-family:'Fira Mono', 'Source Code Pro', monospace;display:block;"><span style="color:#000000;"><span style="color:#0000bb;"><?php<br>session_start</span><span style="color:#007700;">([<br> </span><span style="color:#dd0000;">'cache_limiter' </span><span style="color:#007700;">=> </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;">=> </span><span style="color:#0000bb;">true</span><span style="color:#007700;">,<br>]);<br></span><span style="color:#0000bb;">?></span></span></code></div></div></div></div> <div class="sect2" style="color:#333333;font-family:'Fira Sans', 'Source Sans Pro', Helvetica, Arial, sans-serif;font-size:16px;line-height:24px;background-color:#f2f2f2;"> <h3 class="title" style="margin:0px 0px;overflow:hidden;font-weight:500;color:#793862;clear:both;"><span class="function"><a target="_blank" href="http://php.net/manual/en/function.preg-replace-callback-array.php" class="function" style="border:0px;text-decoration:none;color:#336699;" target="_blank">preg_replace_callback_array()</a></span><a class="genanchor" href="http://php.net/manual/en/migration70.new-features.php#migration70.new-features.preg-repace-callback-array-function" style="border-bottom-style:none;text-decoration:none;border-top-width:0px;border-right-width:0px;border-left-width:0px;" target="_blank"> ¶</a></h3> <p class="para" style="margin:0px 0px;">The new <span class="function"><a target="_blank" href="http://php.net/manual/en/function.preg-replace-callback-array.php" class="function" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank">preg_replace_callback_array()</a></span> function enables code to be written more cleanly when using the <span class="function"><a target="_blank" href="http://php.net/manual/en/function.preg-replace-callback.php" class="function" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank">preg_replace_callback()</a></span> function. Prior to PHP 7, callbacks that needed to be executed per regular expression required the callback function to be polluted with lots of branching.</p> <p class="para" style="margin:0px 0px;">Now, callbacks can be registered to each regular expression using an associative array, where the key is a regular expression and the value is a callback.</p></div> <div class="sect2" style="color:#333333;font-family:'Fira Sans', 'Source Sans Pro', Helvetica, Arial, sans-serif;font-size:16px;line-height:24px;background-color:#f2f2f2;"> <h3 class="title" style="margin:0px 0px;overflow:hidden;font-weight:500;color:#793862;clear:both;"><a target="_blank" href="http://php.net/manual/en/book.csprng.php" class="link" style="border:0px;text-decoration:none;color:#336699;" target="_blank">CSPRNG</a> Functions<a class="genanchor" href="http://php.net/manual/en/migration70.new-features.php#migration70.new-features.csprng-functions" style="border-bottom-style:none;text-decoration:none;border-top-width:0px;border-right-width:0px;border-left-width:0px;" target="_blank"> ¶</a></h3> <p class="para" style="margin:0px 0px;">Two new functions have been added to generate cryptographically secure integers and strings in a cross platform way: <span class="function"><a target="_blank" href="http://php.net/manual/en/function.random-bytes.php" class="function" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank">random_bytes()</a></span> and<span class="function"><a target="_blank" href="http://php.net/manual/en/function.random-int.php" class="function" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank">random_int()</a></span>.</p></div> <div class="sect2" style="color:#333333;font-family:'Fira Sans', 'Source Sans Pro', Helvetica, Arial, sans-serif;font-size:16px;line-height:24px;background-color:#f2f2f2;"> <h3 class="title" style="margin:0px 0px;overflow:hidden;font-weight:500;color:#793862;clear:both;"><span class="function"><a target="_blank" href="http://php.net/manual/en/function.list.php" class="function" style="border:0px;text-decoration:none;color:#336699;" target="_blank">list()</a></span> can always unpack objects implementing <a target="_blank" href="http://php.net/manual/en/class.arrayaccess.php" class="classname" style="border:0px;text-decoration:none;color:#336699;" target="_blank">ArrayAccess</a> <a class="genanchor" href="http://php.net/manual/en/migration70.new-features.php#migration70.new-features.list-arrayaccess" style="border-bottom-style:none;text-decoration:none;border-top-width:0px;border-right-width:0px;border-left-width:0px;" target="_blank">¶</a></h3> <p class="para" style="margin:0px 0px;">Previously, <span class="function"><a target="_blank" href="http://php.net/manual/en/function.list.php" class="function" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank">list()</a></span> was not guaranteed to operate correctly with objects implementing <a target="_blank" href="http://php.net/manual/en/class.arrayaccess.php" class="classname" style="border-bottom-width:1px;border-bottom-style:solid;text-decoration:none;color:#336699;" target="_blank">ArrayAccess</a>. This has been fixed.</p></div>
댓글 분란 또는 분쟁 때문에 전체 댓글이 블라인드 처리되었습니다.