mirror of
https://github.com/php/doc-pt_br.git
synced 2026-03-24 07:02:09 +01:00
192 lines
5.4 KiB
XML
192 lines
5.4 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- EN-Revision: 790f63af6521908477b285ff753e454e118bb989 Maintainer: leonardolara Status: ready --><!-- CREDITS: fernandowobeto,leonardolara -->
|
|
<refentry xml:id="reflectionmethod.construct" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
<refnamediv>
|
|
<refname>ReflectionMethod::__construct</refname>
|
|
<refpurpose>Constrói um ReflectionMethod</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<constructorsynopsis role="ReflectionMethod">
|
|
<modifier>public</modifier> <methodname>ReflectionMethod::__construct</methodname>
|
|
<methodparam><type class="union"><type>object</type><type>string</type></type><parameter>objectOrMethod</parameter></methodparam>
|
|
<methodparam><type>string</type><parameter>method</parameter></methodparam>
|
|
</constructorsynopsis>
|
|
<simpara>Assinatura alternativa (não suportada com argumentos nomeados):</simpara>
|
|
<constructorsynopsis role="ReflectionMethod">
|
|
<modifier>public</modifier> <methodname>ReflectionMethod::__construct</methodname>
|
|
<methodparam><type>string</type><parameter>classMethod</parameter></methodparam>
|
|
</constructorsynopsis>
|
|
<warning>
|
|
<simpara>
|
|
A assinatura alternativa foi descontinuada a partir do PHP 8.4.0,
|
|
use <methodname>ReflectionMethod::createFromMethodName</methodname>
|
|
em seu lugar.
|
|
</simpara>
|
|
</warning>
|
|
<para>
|
|
Constrói um novo <classname>ReflectionMethod</classname>.
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>objectOrMethod</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Nome da classe ou objeto (instância da classe) que contém o método.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>method</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Nome do método.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>classMethod</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Nome da classe e nome do método delimitados por <literal>::</literal>.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="errors">
|
|
&reftitle.errors;
|
|
<para>
|
|
Um <classname>ReflectionException</classname> será lançado se o método fornecido não existir.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Exemplo de <methodname>ReflectionMethod::__construct</methodname></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
class Counter
|
|
{
|
|
private static $c = 0;
|
|
|
|
/**
|
|
* Contador de incremento
|
|
*
|
|
* @final
|
|
* @static
|
|
* @access public
|
|
* @return int
|
|
*/
|
|
final public static function increment()
|
|
{
|
|
return ++self::$c;
|
|
}
|
|
}
|
|
|
|
// Cria uma instância da classe ReflectionMethod
|
|
$method = new ReflectionMethod('Counter', 'increment');
|
|
|
|
// Exibe informações básicas
|
|
printf(
|
|
"===> O método %s%s%s%s%s%s%s '%s' (que é %s)\n" .
|
|
" declarado em %s\n" .
|
|
" linhas %d a %d\n" .
|
|
" tem os modificadores %d[%s]\n",
|
|
$method->isInternal() ? 'internal' : 'user-defined',
|
|
$method->isAbstract() ? ' abstract' : '',
|
|
$method->isFinal() ? ' final' : '',
|
|
$method->isPublic() ? ' public' : '',
|
|
$method->isPrivate() ? ' private' : '',
|
|
$method->isProtected() ? ' protected' : '',
|
|
$method->isStatic() ? ' static' : '',
|
|
$method->getName(),
|
|
$method->isConstructor() ? 'o construtor' : 'um método normal',
|
|
$method->getFileName(),
|
|
$method->getStartLine(),
|
|
$method->getEndline(),
|
|
$method->getModifiers(),
|
|
implode(' ', Reflection::getModifierNames($method->getModifiers()))
|
|
);
|
|
|
|
// Exibe comentário da documentação
|
|
printf("---> Documentação:\n %s\n", var_export($method->getDocComment(), true));
|
|
|
|
// Exibe variáveis estáticas se existirem
|
|
if ($statics= $method->getStaticVariables()) {
|
|
printf("---> Variáveis estáticas: %s\n", var_export($statics, true));
|
|
}
|
|
|
|
// Invoca o método
|
|
printf("---> A chamada resulta em: ");
|
|
var_dump($method->invoke(NULL));
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs.similar;
|
|
<screen>
|
|
<![CDATA[
|
|
===> O método user-defined final public static 'increment' (que é um método normal)
|
|
declarado em in /Users/philip/cvs/phpdoc/test.php
|
|
linhas 14 a 17
|
|
tem os modificadores 261[final public static]
|
|
---> Documentação:
|
|
'/**
|
|
* Contador de incremento
|
|
*
|
|
* @final
|
|
* @static
|
|
* @access public
|
|
* @return int
|
|
*/'
|
|
---> A chamada resulta em: int(1)
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><methodname>ReflectionMethod::export</methodname></member>
|
|
<member><link linkend="language.oop5.decon.constructor">Construtores</link></member>
|
|
</simplelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
</refentry>
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|