Sophie

Sophie

distrib > Mandriva > 2008.1 > i586 > by-pkgid > 703d980c580707c382b4e43e25965bc5 > files > 11832

php-manual-pt_BR-5.2.4-1mdv2008.1.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>Tipos</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="Referência da Linguagem"
HREF="langref.html"><LINK
REL="PREVIOUS"
TITLE="Comentários"
HREF="language.basic-syntax.comments.html"><LINK
REL="NEXT"
TITLE="Booleanos"
HREF="language.types.boolean.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=UTF-8"></HEAD
><BODY
CLASS="chapter"
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="language.basic-syntax.comments.html"
ACCESSKEY="P"
>Anterior</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="language.types.boolean.html"
ACCESSKEY="N"
>Próxima</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="chapter"
><H1
><A
NAME="language.types"
>Capítulo 11. Tipos</A
></H1
><DIV
CLASS="TOC"
><DL
><DT
><B
>Índice</B
></DT
><DT
><A
HREF="language.types.html#language.types.intro"
>Introdução</A
></DT
><DT
><A
HREF="language.types.boolean.html"
>Booleanos</A
></DT
><DT
><A
HREF="language.types.integer.html"
>Inteiros</A
></DT
><DT
><A
HREF="language.types.float.html"
>Números de ponto flutuante</A
></DT
><DT
><A
HREF="language.types.string.html"
>Strings</A
></DT
><DT
><A
HREF="language.types.array.html"
>Arrays</A
></DT
><DT
><A
HREF="language.types.object.html"
>Objetos</A
></DT
><DT
><A
HREF="language.types.resource.html"
>Resource</A
></DT
><DT
><A
HREF="language.types.null.html"
>NULL</A
></DT
><DT
><A
HREF="language.pseudo-types.html"
>Pseudo-tipos utilizados nesta documentação</A
></DT
><DT
><A
HREF="language.types.type-juggling.html"
>Manipulação de tipos</A
></DT
></DL
></DIV
><DIV
CLASS="sect1"
><H1
CLASS="sect1"
><A
NAME="language.types.intro"
>Introdução</A
></H1
><P
>&#13;   O PHP suporta os oitos tipos primitivos.
  </P
><P
>&#13;   São quatros tipos básicos:

   <P
></P
><UL
><LI
><P
>&#13;      <A
HREF="language.types.boolean.html"
><B
CLASS="type"
>boolean</B
></A
>
     </P
></LI
><LI
><P
>&#13;      <A
HREF="language.types.integer.html"
><B
CLASS="type"
>integer</B
></A
>
     </P
></LI
><LI
><P
>&#13;      <A
HREF="language.types.float.html"
><B
CLASS="type"
>float</B
></A
> (número de ponto flutuante, ou também '<A
HREF="language.types.float.html"
><B
CLASS="type"
>double</B
></A
>')
     </P
></LI
><LI
><P
>&#13;      <A
HREF="language.types.string.html"
><B
CLASS="type"
>string</B
></A
>
     </P
></LI
></UL
>

   Dois tipos compostos:

   <P
></P
><UL
><LI
><P
>&#13;      <A
HREF="language.types.array.html"
><B
CLASS="type"
>array</B
></A
>
     </P
></LI
><LI
><P
>&#13;      <A
HREF="language.types.object.html"
><B
CLASS="type"
>object</B
></A
>
     </P
></LI
></UL
>

   E finalmente dois tipos especiais:

   <P
></P
><UL
><LI
><P
>&#13;      <A
HREF="language.types.resource.html"
><B
CLASS="type"
>resource</B
></A
>
     </P
></LI
><LI
><P
>&#13;      <A
HREF="language.types.null.html"
><B
CLASS="type"
>NULL</B
></A
>
     </P
></LI
></UL
>

   Este manual também introduz alguns
   <A
HREF="language.pseudo-types.html"
>pseudo-tipos</A
>
   por razões de legibilidade:

   <P
></P
><UL
><LI
><P
>&#13;      <A
HREF="language.pseudo-types.html#language.types.mixed"
>mixed</A
>
     </P
></LI
><LI
><P
>&#13;      <A
HREF="language.pseudo-types.html#language.types.number"
>number</A
>
     </P
></LI
><LI
><P
>&#13;      <A
HREF="language.pseudo-types.html#language.types.mixed"
>callback</A
>
     </P
></LI
></UL
>
   Você também pode encontrar algumas referências ao tipo "double". Considere o tipo
   double como sendo o float, e os dois nomes existem por razões
   históricas.
  </P
><P
>&#13;   O tipo da variável geralmente não é configurado pelo programador: isto
   é decidido em tempo de execução pelo PHP, dependendo do contexto no qual a
   variável é usada.
  </P
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Nota: </B
>
    Se você quiser checar o tipo e valor de uma certa <A
HREF="language.expressions.html"
>expressão</A
>, utilize
    <A
HREF="function.var-dump.html"
><B
CLASS="function"
>var_dump()</B
></A
>.
   </P
><P
><B
>Nota: </B
>
    Se você simplesmente quiser uma representação legível de seu tipo para
    debugagem, use <A
HREF="function.gettype.html"
><B
CLASS="function"
>gettype()</B
></A
>. Para verificar por certos tipos,
    <SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>não use</I
></SPAN
> <A
HREF="function.gettype.html"
><B
CLASS="function"
>gettype()</B
></A
>, mas sim as funções
    <TT
CLASS="literal"
>is_<TT
CLASS="replaceable"
><I
>type</I
></TT
></TT
>. Vejamos alguns
    exemplos:
    <DIV
CLASS="informalexample"
><P
></P
><A
NAME="AEN2824"
></A
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br />$bool </font><font color="#007700">= </font><font color="#0000BB">TRUE</font><font color="#007700">;&nbsp;&nbsp;&nbsp;</font><font color="#FF8000">// um booleano<br /></font><font color="#0000BB">$str&nbsp;&nbsp;</font><font color="#007700">= </font><font color="#DD0000">"foo"</font><font color="#007700">;&nbsp;&nbsp;</font><font color="#FF8000">// uma string<br /></font><font color="#0000BB">$int&nbsp;&nbsp;</font><font color="#007700">= </font><font color="#0000BB">12</font><font color="#007700">;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#FF8000">// um inteiro<br /><br /></font><font color="#007700">echo </font><font color="#0000BB">gettype</font><font color="#007700">(</font><font color="#0000BB">$bool</font><font color="#007700">); </font><font color="#FF8000">// imprime "boolean"<br /></font><font color="#007700">echo </font><font color="#0000BB">gettype</font><font color="#007700">(</font><font color="#0000BB">$str</font><font color="#007700">);&nbsp;&nbsp;</font><font color="#FF8000">// imprime "string"<br /><br />// Se é um inteiro, incrementa em quatro<br /></font><font color="#007700">if (</font><font color="#0000BB">is_int</font><font color="#007700">(</font><font color="#0000BB">$int</font><font color="#007700">)) {<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$int </font><font color="#007700">+= </font><font color="#0000BB">4</font><font color="#007700">;<br />}<br /><br /></font><font color="#FF8000">// Se $bool é string, imprime<br />// (e não faz nada se não for)<br /></font><font color="#007700">if (</font><font color="#0000BB">is_string</font><font color="#007700">(</font><font color="#0000BB">$bool</font><font color="#007700">)) {<br />&nbsp;&nbsp;&nbsp;&nbsp;echo </font><font color="#DD0000">"String: $bool"</font><font color="#007700">;<br />}<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
><P
></P
></DIV
>
   </P
></BLOCKQUOTE
></DIV
><P
>&#13;   Se você quiser forçar a conversão de uma variável para um certo tipo,
   você pode <A
HREF="language.types.type-juggling.html#language.types.typecasting"
>moldar</A
> (casting) a variável ou
   usar a função <A
HREF="function.settype.html"
><B
CLASS="function"
>settype()</B
></A
> nela.
  </P
><P
>&#13;   Note que uma variável pode ser avaliada com valores diferentes em certas
   situações, dependendo de qual tipo ela é no momento. Para mais informações,
   veja a seção <A
HREF="language.types.type-juggling.html"
>Manipulação de tipos</A
>. Também possa
   ser interressante se interar da
   <A
HREF="types.comparisons.html"
>tabela de conversão de tipos</A
>,
   e seus exemplo de vários comparações relacionadas.
  </P
></DIV
></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="language.basic-syntax.comments.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="language.types.boolean.html"
ACCESSKEY="N"
>Próxima</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Comentários</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="langref.html"
ACCESSKEY="U"
>Acima</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Booleanos</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>