<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >Valores de retorno de função TRUE/FALSE</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="Migrando do PHP/FI 2 para o PHP 3" HREF="migration.html"><LINK REL="PREVIOUS" TITLE="Short-circuited boolean evaluation" HREF="migration.booleval.html"><LINK REL="NEXT" TITLE="Outras incompatibilidades" HREF="migration.other.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="migration.booleval.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" >Apêndice E. Migrando do PHP/FI 2 para o PHP 3</TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="migration.other.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="migration.truefalse" >Valores de retorno de função <TT CLASS="constant" ><B >TRUE</B ></TT >/<TT CLASS="constant" ><B >FALSE</B ></TT ></A ></H1 ><P > A maioria das funções foram re-escritas para que elas retornem <TT CLASS="constant" ><B >TRUE</B ></TT > quando tiverem sucesso e <TT CLASS="constant" ><B >FALSE</B ></TT > quando falharem, ao contrário de 0 e -1 no PHP/FI 2.0, respectivamente. O nove comportamento permite criação de código mais lógico, como <TT CLASS="literal" >$fp = fopen("/your/file") or fail("darn!");</TT >. Por isso, PHP/FI 2.0 não tinha regras claras para o que as funções retornariam se falharem, a maioria desses scripts provavelmente terá de ser checada manualmenta após usar o converto do 2.0 para o 3.0. </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN276454" ></A ><P ><B >Exemplo E-9. Migração do 2.0: valores de retorno, código velho</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> $fp = fopen($file, "r");<br />if ($fp == -1);<br /> echo("Could not open $file for reading<br />\n");<br />endif;</font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN276457" ></A ><P ><B >Exemplo E-10. Migração do 2.0: valores de retorno, código novo</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> $fp = @fopen($file, "r") or print("Could not open $file for reading<br />\n");</font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></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="migration.booleval.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="migration.other.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Short-circuited boolean evaluation</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="migration.html" ACCESSKEY="U" >Acima</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Outras incompatibilidades</TD ></TR ></TABLE ></DIV ></BODY ></HTML >