<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >Backward Incompatible Changes</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="Manual do PHP" HREF="index.html"><LINK REL="UP" TITLE="Migrating from PHP 5.1.x to PHP 5.2.x" HREF="migration52.html"><LINK REL="PREVIOUS" TITLE="Migrating from PHP 5.1.x to PHP 5.2.x" HREF="migration52.html"><LINK REL="NEXT" TITLE="New Error Messages" HREF="migration52.error-messages.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"></HEAD ><BODY CLASS="section" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >Manual do PHP</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="migration52.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" >Apêndice B. Migrating from PHP 5.1.x to PHP 5.2.x</TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="migration52.error-messages.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="migration52.incompatible" >Backward Incompatible Changes</A ></H1 ><P > Although most existing PHP 5 code should work without changes, you should pay attention to the following backward incompatible changes: </P ><P ></P ><UL ><LI ><P > <A HREF="function.getrusage.html" ><B CLASS="function" >getrusage()</B ></A > returns <TT CLASS="constant" ><B >NULL</B ></TT > when passed incompatible arguments as of PHP 5.2.1. </P ></LI ><LI ><P > <A HREF="function.ziparchive-setcommentname.html" ><B CLASS="function" >ZipArchive::setCommentName()</B ></A > returns <TT CLASS="constant" ><B >TRUE</B ></TT > on success as of PHP 5.2.1. </P ></LI ><LI ><P > <A HREF="function.ziparchive-setcommentindex.html" ><B CLASS="function" >ZipArchive::setCommentIndex()</B ></A > returns <TT CLASS="constant" ><B >TRUE</B ></TT > on success as of PHP 5.2.1. </P ></LI ><LI ><P > <B CLASS="function" >SplFileObject::getFilename()</B > returns the filename, not relative/path/to/file, as of PHP 5.2.1. </P ></LI ><LI ><P > Changed priority of <TT CLASS="constant" ><B >PHPRC</B ></TT > environment variable on Win32 </P ><P > The PHPRC environment variable now takes priority over the path stored in the Windows registry. </P ></LI ><LI ><P > CLI SAPI no longer checks cwd for <TT CLASS="filename" >php.ini</TT > or the <TT CLASS="filename" >php-cli.ini</TT > file </P ><P > In PHP 5.1.x an undocumented feature was added that made the CLI binary check the current working directory for a PHP configuration file, potentially leading to unpredictable behavior if an unexpected configuration file were read. This functionality was removed in 5.2.0, and PHP will no longer search CWD for the presence of <TT CLASS="filename" >php.ini</TT > or <TT CLASS="filename" >php-cli.ini</TT > files. See also the <A HREF="features.commandline.html" >command line</A > section of the manual. </P ></LI ><LI ><P > Added a warning when performing modulus 0 operations </P ><P > In earlier versions of PHP, performing integer % 0 did not emit any warning messages, instead returning an unexpected return value of <TT CLASS="constant" ><B >FALSE</B ></TT >. As of PHP 5.2.0, this operation will emit an <TT CLASS="constant" ><B >E_WARNING</B ></TT >, as is the case in all other instances where division by zero is performed. </P ><DIV CLASS="informalexample" ><P ></P ><A NAME="AEN274980" ></A ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /></font><font color="#007700">print </font><font color="#0000BB">10 </font><font color="#007700">% </font><font color="#0000BB">0</font><font color="#007700">;<br /></font><font color="#FF8000">/* Warning: Division by zero in filename on line n */<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P ></P ></DIV ></LI ><LI ><P > Changed <B CLASS="function" >__toString()</B > to be called wherever applicable. </P ><P > The magic method <B CLASS="function" >__toString()</B > will now be called in a string context, that is, anywhere an object is used as a string. </P ><P > The fallback of returning a string that contains the object identifier was dropped in PHP 5.2.0. It became problematic because an object identifier cannot be considered unique. This change will mean that your application is flawed if you have relied on the object identifier as a return value. An attempt to use that value as a string will now result in a catchable fatal error. </P ><DIV CLASS="informalexample" ><P ></P ><A NAME="AEN274988" ></A ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /></font><font color="#007700">class </font><font color="#0000BB">foo </font><font color="#007700">{}<br /></font><font color="#0000BB">$foo </font><font color="#007700">= new </font><font color="#0000BB">foo</font><font color="#007700">;<br />print </font><font color="#0000BB">$foo</font><font color="#007700">;<br /></font><font color="#FF8000">/* Catchable fatal error: Object of class foo could<br /> not be converted to string in filename on line n */<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P ></P ></DIV ><P > Even with <B CLASS="function" >__toString()</B >, objects cannot be used as array indices or keys. We may add built-in hash support for this at a later date, but as of PHP 5.2.x you will need to either provide your own hashing or use the new SPL function <A HREF="function.spl-object-hash.html" ><B CLASS="function" >spl_object_hash()</B ></A >. </P ><P > Exceptions can not be thrown from <B CLASS="function" >__toString()</B > methods. </P ><DIV CLASS="informalexample" ><P ></P ><A NAME="AEN274995" ></A ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /></font><font color="#007700">class </font><font color="#0000BB">foo </font><font color="#007700">{<br /> </font><font color="#0000BB">public </font><font color="#007700">function </font><font color="#0000BB">__toString</font><font color="#007700">() {<br /> </font><font color="#0000BB">throw </font><font color="#007700">new </font><font color="#0000BB">Exception</font><font color="#007700">;<br /> }<br />}<br /><br /></font><font color="#0000BB">try </font><font color="#007700">{<br /> print new </font><font color="#0000BB">foo</font><font color="#007700">;<br /> </font><font color="#FF8000">/* Fatal error: Method foo::__toString() must<br /> not throw an exception in filename on line n */<br /></font><font color="#007700">} </font><font color="#0000BB">catch</font><font color="#007700">(</font><font color="#0000BB">Exception $e</font><font color="#007700">) {}<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P ></P ></DIV ></LI ><LI ><P > Dropped abstract static class functions. </P ><P > Due to an oversight, PHP 5.0.x and 5.1.x allowed abstract static functions in classes. As of PHP 5.2.x, only interfaces can have them. </P ><DIV CLASS="informalexample" ><P ></P ><A NAME="AEN275000" ></A ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br />abstract </font><font color="#007700">class </font><font color="#0000BB">foo </font><font color="#007700">{<br /> </font><font color="#0000BB">abstract </font><font color="#007700">static function </font><font color="#0000BB">bar</font><font color="#007700">();<br /> </font><font color="#FF8000">/* Strict Standards: Static function foo::bar()<br /> should not be abstract in filename on line n */<br /></font><font color="#007700">}<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P ></P ></DIV ></LI ><LI ><P > Added RFC2397 (<TT CLASS="literal" >data:</TT > stream) support. </P ><P > The introduction of the 'data' URL scheme has the potential to lead to a change of behavior under Windows. If you are working with a <ACRONYM CLASS="acronym" >NTFS</ACRONYM > file system and making use of meta streams in your application, and if you just happen to be using a file with the name 'data:' that is accessed without any path information - it won't work any more. The fix is to use the 'file:' protocol when accessing it. </P ><P > See also <A HREF="http://www.faqs.org/rfcs/rfc2397" TARGET="_top" >RFC 2397</A > </P ><DIV CLASS="informalexample" ><P ></P ><A NAME="AEN275009" ></A ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /></font><font color="#FF8000">/* when allow_url_include is OFF (default) */<br /></font><font color="#007700">include </font><font color="#DD0000">"data:;base64,PD9waHAgcGhwaW5mbygpOz8+"</font><font color="#007700">;<br /></font><font color="#FF8000">/* Warning: include(): URL file-access is disabled<br /> in the server configuration in filename on line n */<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P ></P ></DIV ></LI ></UL ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="migration52.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Principal</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="migration52.error-messages.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Migrating from PHP 5.1.x to PHP 5.2.x</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="migration52.html" ACCESSKEY="U" >Acima</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >New Error Messages</TD ></TR ></TABLE ></DIV ></BODY ></HTML >