1
0
mirror of https://github.com/php/doc-es.git synced 2026-03-26 08:22:08 +01:00
Files
archived-doc-es/reference/reflection/reflectionproperty/construct.xml
Pedro Antonio Gil Rodríguez e32efc6885 Updated to the most recent version
git-svn-id: https://svn.php.net/repository/phpdoc/es/trunk@330776 c90b9560-bf6c-de11-be94-00142212c4b1
2013-07-06 16:56:25 +00:00

196 lines
4.6 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 656d1610af1a960d87c8b7056e54d0d4c75fb123 Maintainer: chuso Status: ready -->
<!-- Reviewed: no -->
<refentry xml:id="reflectionproperty.construct" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>ReflectionProperty::__construct</refname>
<refpurpose>Construye un objeto de tipo ReflectionProperty</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier> <methodname>ReflectionProperty::__construct</methodname>
<methodparam><type>mixed</type><parameter>class</parameter></methodparam>
<methodparam><type>string</type><parameter>name</parameter></methodparam>
</methodsynopsis>
<para>
</para>
&warn.undocumented.func;
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>class</parameter></term>
<listitem>
<para>
Nombre de la clase que contiene la propiedad.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>name</parameter></term>
<listitem>
<para>
Nombre de la propiedad que se desea reflexionar.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
&return.void;
</para>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
<para>
Si se tratara de consultar o modificar propiedades privadas o protegidas
de la clase, se lanzaría una excepción.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>Ejemplo de <methodname>ReflectionProperty::__construct</methodname></title>
<programlisting role="php">
<![CDATA[
<?php
class Texto
{
public $longitud = 5;
}
// Crea una instancia de la clase ReflectionProperty
$prop = new ReflectionProperty('Texto', 'longitud');
// Muestra información básica
printf(
"===> La propiedad %s%s%s%s '%s' (que está %s)\n" .
" con los modificadores %s\n",
$prop->isPublic() ? ' pública' : '',
$prop->isPrivate() ? ' privada' : '',
$prop->isProtected() ? ' protegida' : '',
$prop->isStatic() ? ' estática' : '',
$prop->getName(),
$prop->isDefault() ? 'declarada en tiempo de compilación' : 'creada en tiempo de ejecución',
var_export(Reflection::getModifierNames($prop->getModifiers()), 1)
);
// Crea una instancia de Texto
$obj= new Texto();
// Obtiene el valor actual
printf("---> Valor: ");
var_dump($prop->getValue($obj));
// Cambiar valor
$prop->setValue($obj, 10);
printf("---> Al establecer como valor 10, su nuevo valor es: ");
var_dump($prop->getValue($obj));
// Volcar objeto
var_dump($obj);
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
===> La propiedad pública 'longitud' (que está declarada en tiempo de compilación)
con los modificadores array (
0 => 'public',
)
---> Valor: int(5)
---> Al establecer como valor 10, su nuevo valor es: int(10)
object(Texto)#2 (1) {
["longitud"]=>
int(10)
}
]]>
</screen>
</example>
<example>
<title>Consultar el valor de propiedades privadas y protegidas con la clase <classname>ReflectionProperty</classname></title>
<programlisting role="php">
<![CDATA[
<?php
class Foo {
public $x = 1;
protected $y = 2;
private $z = 3;
}
$obj = new Foo;
$prop = new ReflectionProperty('Foo', 'y');
$prop->setAccessible(true); /* Desde PHP 5.3.0 */
var_dump($prop->getValue($obj)); // int(2)
$prop = new ReflectionProperty('Foo', 'z');
$prop->setAccessible(true); /* Desde PHP 5.3.0 */
var_dump($prop->getValue($obj)); // int(2)
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
int(2)
int(3)
]]>
</screen>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><methodname>ReflectionProperty::getName</methodname></member>
<member><link linkend="language.oop5.decon.constructor">Constructores</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
-->