Sophie

Sophie

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

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
>Sobrecarga de propriedades e métodos de objetos</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 das Funções"
HREF="funcref.html"><LINK
REL="PREVIOUS"
TITLE="deaggregate"
HREF="function.deaggregate.html"><LINK
REL="NEXT"
TITLE="overload"
HREF="function.overload.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=UTF-8"></HEAD
><BODY
CLASS="reference"
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="function.deaggregate.html"
ACCESSKEY="P"
>Anterior</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.overload.html"
ACCESSKEY="N"
>Próxima</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="reference"
><A
NAME="ref.overload"
></A
><DIV
CLASS="TITLEPAGE"
><H1
CLASS="title"
>CVI. Sobrecarga de propriedades e métodos de objetos</H1
><DIV
CLASS="PARTINTRO"
><A
NAME="AEN150597"
></A
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="overload.intro"
>Introdução</A
></H1
><P
>&#13;     O propósito desta extensão é permitir a sobrecarga de propriedades
     de acesso e metodos de objetos. Somente uma função é definida
     nesta extensão, <A
HREF="function.overload.html"
><B
CLASS="function"
>overload()</B
></A
> que
     recebe o nome da classe que deve ter esta funcionalidade
     habilitada. A classe especificada tem que definir os metodos para
     ter esta funcionalidade: <TT
CLASS="literal"
>__get()</TT
>,
     <TT
CLASS="literal"
>__set()</TT
> e <TT
CLASS="literal"
>__call()</TT
>
     respectivamente para leitura/escrita das propriedades, ou chamar um metodo.
     Desta forma a sobrecarga pode ser seletiva: Dentro destas funções
     a sobrecarga é desabilitada de forma que você possa acessar
     propriedades do objeto normalmente.
    </P
><DIV
CLASS="warning"
><P
></P
><TABLE
CLASS="warning"
BORDER="1"
WIDTH="100%"
><TR
><TD
ALIGN="CENTER"
><B
>Atenção</B
></TD
></TR
><TR
><TD
ALIGN="LEFT"
><P
>Este módulo é
 <SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>EXPERIMENTAL</I
></SPAN
>. Isso quer dizer que o comportamento neste módulo ---
 incluindo suas funções e seus nomes, e TUDO mais que está documentado
 sobre esse módulo --- poderá mudar em futuras versões do PHP, SEM QUALQUER NOTIFICAÇÃO.
 Esteja avisado, e use este módulo por sua própria conta e risco.</P
></TD
></TR
></TABLE
></DIV
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="overload.requirements"
>Dependências</A
></H1
><P
>Nenhuma biblioteca externa é necessária para compilar esta extensão.</P
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="overload.installation"
>Instalação</A
></H1
><P
>&#13;  In order to use these functions, you must compile
  PHP with the <CODE
CLASS="option"
>--enable-overload</CODE
> option.
  Starting with PHP 4.3.0 this extension is enabled by default. You can
  disable overload support with
  <CODE
CLASS="option"
>--disable--overload</CODE
>.
 </P
><P
>A versão para Windows do <TT
CLASS="literal"
>PHP</TT
>
 tem suporte embutido para esta extensão. Você não precisa carregar nenhuma extensão
 adicional para utilizar essas funções.</P
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Nota: </B
>
   Builtin support for overload is available with PHP 4.3.0.
  </P
></BLOCKQUOTE
></DIV
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="overload.configuration"
>Configurações em execução</A
></H1
><P
>Esta extensão não define nenhum parâmetro de configuração no <TT
CLASS="filename"
>php.ini</TT
>.</P
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="overload.resources"
>Tipos Resource</A
></H1
><P
>Esta extensão não possui nenhum tipo resource.</P
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="overload.constants"
>Constantes pré-definidas</A
></H1
><P
>Esta extensão não possui nenhuma constante.</P
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="overload.examples"
>Exemplos</A
></H1
><P
>&#13;     Alguns exemplos simples da utilização da função
     <A
HREF="function.overload.html"
><B
CLASS="function"
>overload()</B
></A
>:
     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN150634"
></A
><P
><B
>Exemplo 1. Sobrecarga de uma classe no PHP</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br /><br /></font><font color="#007700">class </font><font color="#0000BB">OO<br /></font><font color="#007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;var </font><font color="#0000BB">$a </font><font color="#007700">= </font><font color="#0000BB">111</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;var </font><font color="#0000BB">$elem </font><font color="#007700">= array(</font><font color="#DD0000">'b' </font><font color="#007700">=&gt; </font><font color="#0000BB">9</font><font color="#007700">, </font><font color="#DD0000">'c' </font><font color="#007700">=&gt; </font><font color="#0000BB">42</font><font color="#007700">);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#FF8000">// Metodo callback para pegar uma propriedade<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">function </font><font color="#0000BB">__get</font><font color="#007700">(</font><font color="#0000BB">$prop_name</font><font color="#007700">, &amp;</font><font color="#0000BB">$prop_value</font><font color="#007700">)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (isset(</font><font color="#0000BB">$this</font><font color="#007700">-&gt;</font><font color="#0000BB">elem</font><font color="#007700">[</font><font color="#0000BB">$prop_name</font><font color="#007700">])) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$prop_value </font><font color="#007700">= </font><font color="#0000BB">$this</font><font color="#007700">-&gt;</font><font color="#0000BB">elem</font><font color="#007700">[</font><font color="#0000BB">$prop_name</font><font color="#007700">];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return </font><font color="#0000BB">true</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} else {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return </font><font color="#0000BB">false</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#FF8000">// Metodo callback para definir uma propriedade<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">function </font><font color="#0000BB">__set</font><font color="#007700">(</font><font color="#0000BB">$prop_name</font><font color="#007700">, </font><font color="#0000BB">$prop_value</font><font color="#007700">)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$this</font><font color="#007700">-&gt;</font><font color="#0000BB">elem</font><font color="#007700">[</font><font color="#0000BB">$prop_name</font><font color="#007700">] = </font><font color="#0000BB">$prop_value</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return </font><font color="#0000BB">true</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /></font><font color="#FF8000">// Aqui nós sobrecarregamos o objeto OO<br /></font><font color="#0000BB">overload</font><font color="#007700">(</font><font color="#DD0000">'OO'</font><font color="#007700">);<br /><br /></font><font color="#0000BB">$o </font><font color="#007700">= new </font><font color="#0000BB">OO</font><font color="#007700">;<br />print </font><font color="#DD0000">"</font><font color="#007700">\$</font><font color="#DD0000">o</font><font color="#007700">-&gt;</font><font color="#DD0000">a: $o</font><font color="#007700">-&gt;</font><font color="#DD0000">a</font><font color="#007700">\n</font><font color="#DD0000">"</font><font color="#007700">; </font><font color="#FF8000">// imprime: $o-&gt;a:<br /></font><font color="#007700">print </font><font color="#DD0000">"</font><font color="#007700">\$</font><font color="#DD0000">o</font><font color="#007700">-&gt;</font><font color="#DD0000">b: $o</font><font color="#007700">-&gt;</font><font color="#DD0000">b</font><font color="#007700">\n</font><font color="#DD0000">"</font><font color="#007700">; </font><font color="#FF8000">// imprime: $o-&gt;b: 9<br /></font><font color="#007700">print </font><font color="#DD0000">"</font><font color="#007700">\$</font><font color="#DD0000">o</font><font color="#007700">-&gt;</font><font color="#DD0000">c: $o</font><font color="#007700">-&gt;</font><font color="#DD0000">c</font><font color="#007700">\n</font><font color="#DD0000">"</font><font color="#007700">; </font><font color="#FF8000">// imprime: $o-&gt;c: 42<br /></font><font color="#007700">print </font><font color="#DD0000">"</font><font color="#007700">\$</font><font color="#DD0000">o</font><font color="#007700">-&gt;</font><font color="#DD0000">d: $o</font><font color="#007700">-&gt;</font><font color="#DD0000">d</font><font color="#007700">\n</font><font color="#DD0000">"</font><font color="#007700">; </font><font color="#FF8000">// imprime: $o-&gt;d:<br /><br />// adicionar um novo intem para o array $elem em OO<br /></font><font color="#0000BB">$o</font><font color="#007700">-&gt;</font><font color="#0000BB">x </font><font color="#007700">= </font><font color="#0000BB">56</font><font color="#007700">;<br /><br /></font><font color="#FF8000">// iniciar stdclass (é integrada no PHP 4)<br />// $var não é sobrecarregada!<br /></font><font color="#0000BB">$val </font><font color="#007700">= new </font><font color="#0000BB">stdclass</font><font color="#007700">;<br /></font><font color="#0000BB">$val</font><font color="#007700">-&gt;</font><font color="#0000BB">prop </font><font color="#007700">= </font><font color="#0000BB">555</font><font color="#007700">;<br /><br /></font><font color="#FF8000">// Que "a" seja um array com o objeto $val dentro dele<br />// mas __set() o colocará no array $elem<br /></font><font color="#0000BB">$o</font><font color="#007700">-&gt;</font><font color="#0000BB">a </font><font color="#007700">= array(</font><font color="#0000BB">$val</font><font color="#007700">);<br /></font><font color="#0000BB">var_dump</font><font color="#007700">(</font><font color="#0000BB">$o</font><font color="#007700">-&gt;</font><font color="#0000BB">a</font><font color="#007700">[</font><font color="#0000BB">0</font><font color="#007700">]-&gt;</font><font color="#0000BB">prop</font><font color="#007700">);<br /><br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
    </P
><DIV
CLASS="warning"
><P
></P
><TABLE
CLASS="warning"
BORDER="1"
WIDTH="100%"
><TR
><TD
ALIGN="CENTER"
><B
>Atenção</B
></TD
></TR
><TR
><TD
ALIGN="LEFT"
><P
>&#13;      Como esta é uma extensão experimental, nem todas as coisas
      funcionam. Não existe ainda suporte para <TT
CLASS="literal"
>__call()</TT
>
      e você somente pode fazer a sobrecaraga das operações get e set para
      propriedades. Você não pode invocar
      as chamadas originais da classe
      e <TT
CLASS="literal"
>__set()</TT
> somente funciona até um nível
      de acesso de propriedades.
     </P
></TD
></TR
></TABLE
></DIV
></DIV
></DIV
><DIV
CLASS="TOC"
><DL
><DT
><B
>Índice</B
></DT
><DT
><A
HREF="function.overload.html"
>overload</A
>&nbsp;--&nbsp;Ativa a chamada sobrecarregada de propriedades e métodos para uma classe</DT
></DL
></DIV
></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="function.deaggregate.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="function.overload.html"
ACCESSKEY="N"
>Próxima</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>deaggregate</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="funcref.html"
ACCESSKEY="U"
>Acima</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>overload</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>