php-doc-en/reference/reflection/reflectionproperty/setvalue.xml
Peter Cowburn c0575c87fb typofix
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@313130 c90b9560-bf6c-de11-be94-00142212c4b1
2011-07-11 11:10:09 +00:00

144 lines
3.7 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="reflectionproperty.setvalue" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>ReflectionProperty::setValue</refname>
<refpurpose>Set property value</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier> <type>void</type><methodname>ReflectionProperty::setValue</methodname>
<methodparam><type>object</type><parameter>object</parameter></methodparam>
<methodparam><type>mixed</type><parameter>value</parameter></methodparam>
</methodsynopsis>
<methodsynopsis>
<modifier>public</modifier> <type>void</type><methodname>ReflectionProperty::setValue</methodname>
<methodparam><type>mixed</type><parameter>value</parameter></methodparam>
</methodsynopsis>
<para>
Sets (changes) the property's value.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>object</parameter></term>
<listitem>
<para>
If the property is non-static an object must be provided to change
the property on. If the property is static this parameter is left
out and only <parameter>value</parameter> needs to be provided.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>value</parameter></term>
<listitem>
<para>
The new value.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
&return.void;
</para>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
<para>
Throws a <classname>ReflectionException</classname> if the property is inaccessible.
You can make a protected or private property accessible using
<methodname>ReflectionProperty::setAccessible</methodname>.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><methodname>ReflectionProperty::setValue</methodname> example</title>
<programlisting role="php">
<![CDATA[
<?php
class Foo {
public static $staticProperty;
public $property;
protected $privateProperty;
}
$reflectionClass = new ReflectionClass('Foo');
$reflectionClass->getProperty('staticProperty')->setValue('foo');
var_dump(Foo::$staticProperty);
$foo = new Foo;
$reflectionClass->getProperty('property')->setValue($foo, 'bar');
var_dump($foo->property);
$reflectionProperty = $reflectionClass->getProperty('privateProperty');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue($foo, 'foobar');
var_dump($reflectionProperty->getValue($foo));
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
string(3) "foo"
string(3) "bar"
string(6) "foobar"
]]>
</screen>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><methodname>ReflectionProperty::getValue</methodname></member>
<member><methodname>ReflectionProperty::setAccessible</methodname></member>
<member><methodname>ReflectionClass::setStaticPropertyValue</methodname></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
-->