<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Backward incompatible changes</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="migration56.html">Migrating from PHP 5.5.x to PHP 5.6.x</a></div> <div class="next" style="text-align: right; float: right;"><a href="migration56.new-features.html">New features</a></div> <div class="up"><a href="migration56.html">Migrating from PHP 5.5.x to PHP 5.6.x</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="migration56.incompatible" class="sect1"> <h2 class="title">Backward incompatible changes</h2> <p class="simpara"> Although most existing PHP 5 code should work without changes, please take note of some backward incompatible changes: </p> <div class="sect2" id="migration56.incompatible.array-keys"> <h3 class="title">Array keys won't be overwritten when defining an array as a property of a class via an array literal</h3> <p class="para"> Previously, arrays declared as class properties which mixed explicit and implicit keys could have array elements silently overwritten if an explicit key was the same as a sequential implicit key. For example: </p> <div class="informalexample"> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /></span><span style="color: #007700">class </span><span style="color: #0000BB">C </span><span style="color: #007700">{<br /> const </span><span style="color: #0000BB">ONE </span><span style="color: #007700">= </span><span style="color: #0000BB">1</span><span style="color: #007700">;<br /> public </span><span style="color: #0000BB">$array </span><span style="color: #007700">= [<br /> </span><span style="color: #0000BB">self</span><span style="color: #007700">::</span><span style="color: #0000BB">ONE </span><span style="color: #007700">=> </span><span style="color: #DD0000">'foo'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'bar'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'quux'</span><span style="color: #007700">,<br /> ];<br />}<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">((new </span><span style="color: #0000BB">C</span><span style="color: #007700">)-></span><span style="color: #0000BB">array</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <p class="para">Output of the above example in PHP 5.5:</p> <div class="example-contents screen"> <div class="cdata"><pre> array(2) { [0]=> string(3) "bar" [1]=> string(4) "quux" } </pre></div> </div> <p class="para">Output of the above example in PHP 5.6:</p> <div class="example-contents screen"> <div class="cdata"><pre> array(3) { [1]=> string(3) "foo" [2]=> string(3) "bar" [3]=> string(4) "quux" } </pre></div> </div> </div> </div> <div class="sect2" id="migration56.incompatible.json-decode"> <h3 class="title"><span class="function"><a href="function.json-decode.html" class="function">json_decode()</a></span> strictness</h3> <p class="para"> <span class="function"><a href="function.json-decode.html" class="function">json_decode()</a></span> now rejects non-lowercase variants of the JSON literals <em>true</em>, <em>false</em> and <em>null</em> at all times, as per the JSON specification, and sets <span class="function"><a href="function.json-last-error.html" class="function">json_last_error()</a></span> accordingly. Previously, inputs to <span class="function"><a href="function.json-decode.html" class="function">json_decode()</a></span> that consisted solely of one of these values in upper or mixed case were accepted. </p> <p class="para"> This change will only affect cases where invalid JSON was being passed to <span class="function"><a href="function.json-decode.html" class="function">json_decode()</a></span>: valid JSON input is unaffected and will continue to be parsed normally. </p> </div> <div class="sect2" id="migration56.incompatible.peer-verification"> <h3 class="title">Stream wrappers now verify peer certificates and host names by default when using SSL/TLS</h3> <p class="para"> All encrypted client streams now enable peer verification by default. By default, this will use OpenSSL's default CA bundle to verify the peer certificate. In most cases, no changes will need to be made to communicate with servers with valid SSL certificates, as distributors generally configure OpenSSL to use known good CA bundles. </p> <p class="para"> The default CA bundle may be overridden on a global basis by setting either the openssl.cafile or openssl.capath configuration setting, or on a per request basis by using the <a href="context.ssl.html#context.ssl.cafile" class="link"><code class="parameter">cafile</code></a> or <a href="context.ssl.html#context.ssl.capath" class="link"><code class="parameter">capath</code></a> context options. </p> <p class="para"> While not recommended in general, it is possible to disable peer certificate verification for a request by setting the <a href="context.ssl.html#context.ssl.verify-peer" class="link"><code class="parameter">verify_peer</code></a> context option to <strong><code>FALSE</code></strong>, and to disable peer name validation by setting the <a href="context.ssl.html#context.ssl.verify-peer-name" class="link"><code class="parameter">verify_peer_name</code></a> context option to <strong><code>FALSE</code></strong>. </p> </div> <div class="sect2" id="migration56.incompatible.gmp"> <h3 class="title"><a href="book.gmp.html" class="link">GMP</a> resources are now objects</h3> <p class="para"> <a href="book.gmp.html" class="link">GMP</a> resources are now objects. The functional API implemented in the GMP extension has not changed, and code should run unmodified unless it checks explicitly for a resource using <span class="function"><a href="function.is-resource.html" class="function">is_resource()</a></span> or similar. </p> </div> <div class="sect2" id="migration56.incompatible.mcrypt"> <h3 class="title"><a href="book.mcrypt.html" class="link">Mcrypt</a> functions now require valid keys and IVs</h3> <p class="para"> <span class="function"><a href="function.mcrypt-encrypt.html" class="function">mcrypt_encrypt()</a></span>, <span class="function"><a href="function.mcrypt-decrypt.html" class="function">mcrypt_decrypt()</a></span>, <span class="function"><a href="function.mcrypt-cbc.html" class="function">mcrypt_cbc()</a></span>, <span class="function"><a href="function.mcrypt-cfb.html" class="function">mcrypt_cfb()</a></span>, <span class="function"><a href="function.mcrypt-ecb.html" class="function">mcrypt_ecb()</a></span>, <span class="function"><a href="function.mcrypt-generic.html" class="function">mcrypt_generic()</a></span> and <span class="function"><a href="function.mcrypt-ofb.html" class="function">mcrypt_ofb()</a></span> will no longer accept keys or IVs with incorrect sizes, and block cipher modes that require IVs will now fail if an IV isn't provided. </p> </div> <div class="sect2" id="migration56.incompatible.curl"> <h3 class="title"><a href="book.curl.html" class="link">cURL</a> file uploads</h3> <p class="para"> Uploads using the @file syntax now require CURLOPT_SAFE_UPLOAD to be set to <strong><code>FALSE</code></strong>. <a href="class.curlfile.html" class="classname">CURLFile</a> should be used instead. </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="migration56.html">Migrating from PHP 5.5.x to PHP 5.6.x</a></div> <div class="next" style="text-align: right; float: right;"><a href="migration56.new-features.html">New features</a></div> <div class="up"><a href="migration56.html">Migrating from PHP 5.5.x to PHP 5.6.x</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>