Sophie

Sophie

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

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
>Palavra-Chave 'static'</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="Classes e Objetos (PHP 5)"
HREF="language.oop5.html"><LINK
REL="PREVIOUS"
TITLE="Operador de Resolução de Escopo (::)"
HREF="language.oop5.paamayim-nekudotayim.html"><LINK
REL="NEXT"
TITLE="Constantes do Objeto"
HREF="language.oop5.constants.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=UTF-8"></HEAD
><BODY
CLASS="sect1"
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.oop5.paamayim-nekudotayim.html"
ACCESSKEY="P"
>Anterior</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Capítulo 19. Classes e Objetos (PHP 5)</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="language.oop5.constants.html"
ACCESSKEY="N"
>Próxima</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="sect1"
><H1
CLASS="sect1"
><A
NAME="language.oop5.static"
>Palavra-Chave 'static'</A
></H1
><P
>&#13;   Declarar membros ou métodos de uma classe como estáticos faz deles
   acessíveis sem precisar instanciar a classe. Um membro declarados como
   estático não pode ser acessado com um objeto instanciado da classe (embora
   métodos estáticos podem).
  </P
><P
>&#13;   A declara�o static deve estar depois da declara�o de visibilidade. Por
   compatibilidade com o PHP 4, se nenhum declara�o de <A
HREF="language.oop5.visibility.html"
>visibilidade</A
> for usada, ent�
   o membro ou m�odo ser�tratado
   como se fosse declarado como <TT
CLASS="literal"
>public static</TT
>.
  </P
><P
>&#13;   Como m�odos est�icos podem ser chamados sem uma inst�cia do
   objeto ter sido criada, a pseudo-vari�el <CODE
CLASS="varname"
>$this</CODE
> n�
   �dispon�el dentro do m�odo declarado como est�ico.
  </P
><P
>&#13;   De fato, chamadas a m�odos <TT
CLASS="literal"
>est�icos</TT
> s� resolvidas em tempo
   de compila�o. Quando usando um nome de classe expl�ito o m�odo j��identificado
   completamente e nenhuma das regras de heran� se aplicam. Se a chamada for feita por
   <TT
CLASS="literal"
>self</TT
> ent� <TT
CLASS="literal"
>self</TT
> �traduzido para
   a classe atual, isso � a classe �qual o c�igo pertence. Aqui tamb� n�
   se aplicam as regras de heran�.
  </P
><P
>&#13;   Propriedades est�icas n� podem ser acessadas pelo objeto usando o operador
   seta -&#62;.
  </P
><P
>&#13;    Chamar m�odos n� est�icos de maneira est�ica gera um aviso de n�el E_STRICT.
  </P
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN5718"
></A
><P
><B
>Exemplo 19-14. Exemplo de membro est�ico</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br /></font><font color="#007700">class </font><font color="#0000BB">Foo<br /></font><font color="#007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">public </font><font color="#007700">static </font><font color="#0000BB">$meu_estatico </font><font color="#007700">= </font><font color="#DD0000">'foo'</font><font color="#007700">;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">public </font><font color="#007700">function </font><font color="#0000BB">valorEstatico</font><font color="#007700">() {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return </font><font color="#0000BB">self</font><font color="#007700">::</font><font color="#0000BB">$meu_estatico</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br />class </font><font color="#0000BB">Bar </font><font color="#007700">extends </font><font color="#0000BB">Foo<br /></font><font color="#007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">public </font><font color="#007700">function </font><font color="#0000BB">fooEstatico</font><font color="#007700">() {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return </font><font color="#0000BB">parent</font><font color="#007700">::</font><font color="#0000BB">$meu_estatico</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /><br />print </font><font color="#0000BB">Foo</font><font color="#007700">::</font><font color="#0000BB">$meu_estatico </font><font color="#007700">. </font><font color="#DD0000">"\n"</font><font color="#007700">;<br /><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">-&gt;</font><font color="#0000BB">valorEstatico</font><font color="#007700">() . </font><font color="#DD0000">"\n"</font><font color="#007700">;<br />print </font><font color="#0000BB">$foo</font><font color="#007700">-&gt;</font><font color="#0000BB">$meu_estatico </font><font color="#007700">. </font><font color="#DD0000">"\n"</font><font color="#007700">;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#FF8000">// "Propriedade" Indefinida $meu_estatico<br /><br />// $foo::$meu_estatico n� �poss�el<br /><br /></font><font color="#007700">print </font><font color="#0000BB">Bar</font><font color="#007700">::</font><font color="#0000BB">$meu_estatico </font><font color="#007700">. </font><font color="#DD0000">"\n"</font><font color="#007700">;<br /></font><font color="#0000BB">$bar </font><font color="#007700">= new </font><font color="#0000BB">Bar</font><font color="#007700">();<br />print </font><font color="#0000BB">$bar</font><font color="#007700">-&gt;</font><font color="#0000BB">fooEstatico</font><font color="#007700">() . </font><font color="#DD0000">"\n"</font><font color="#007700">;<br /></font><font color="#0000BB">?&gt;</font>
</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="AEN5721"
></A
><P
><B
>Exemplo 19-15. Exemplo de m�odo est�ico</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br /></font><font color="#007700">class </font><font color="#0000BB">Foo </font><font color="#007700">{<br />&nbsp;&nbsp;</font><font color="#0000BB">public </font><font color="#007700">static function </font><font color="#0000BB">umMetodoEstatico</font><font color="#007700">() {<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#FF8000">// ...<br />&nbsp;&nbsp;</font><font color="#007700">}<br />}<br /><br /></font><font color="#0000BB">Foo</font><font color="#007700">::</font><font color="#0000BB">umMetodoEstatico</font><font color="#007700">();<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
></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.oop5.paamayim-nekudotayim.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.oop5.constants.html"
ACCESSKEY="N"
>Próxima</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Operador de Resolução de Escopo (::)</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="language.oop5.html"
ACCESSKEY="U"
>Acima</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Constantes do Objeto</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>