mirror of
https://github.com/php/doc-fr.git
synced 2026-03-24 07:02:06 +01:00
* Translate hooks reflection * Sync reflectionproperty hooks with EN * Sync propertyhooktype * Sync php example in reflectionproperty
141 lines
3.8 KiB
XML
141 lines
3.8 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- EN-Revision: 49ef347a18b037370b6bd8e690096270f1780153 Maintainer: Fan2Shrek Status: ready -->
|
|
<!-- Reviewed: yes -->
|
|
<refentry xml:id="reflectionproperty.setrawvalue" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
<refnamediv>
|
|
<refname>ReflectionProperty::setRawValue</refname>
|
|
<refpurpose>Définit la valeur d'une propriété, en contournant un hook de définition s'il est défini</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis role="ReflectionProperty">
|
|
<modifier>public</modifier> <type>void</type><methodname>ReflectionProperty::setRawValue</methodname>
|
|
<methodparam><type>object</type><parameter>object</parameter></methodparam>
|
|
<methodparam><type>mixed</type><parameter>value</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<simpara>
|
|
Définit la valeur d'une propriété, en contournant un <literal>set</literal> hook s'il est défini.
|
|
</simpara>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>object</parameter></term>
|
|
<listitem>
|
|
<simpara>
|
|
L'objet sur lequel définir la valeur de la propriété.
|
|
</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>value</parameter></term>
|
|
<listitem>
|
|
<simpara>
|
|
La valeur à écrire. Elle doit toujours être valide selon le type de la propriété.
|
|
</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<simpara>
|
|
&return.void;
|
|
</simpara>
|
|
</refsect1>
|
|
|
|
<refsect1 role="errors">
|
|
&reftitle.errors;
|
|
<simpara>
|
|
Si la propriété est virtuelle, une <classname>Error</classname> sera lancée,
|
|
car il n'y a pas de valeur brute à définir.
|
|
</simpara>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<example xml:id="reflectionproperty.setrawvalue.example.basic">
|
|
<title>Exemple de <methodname>ReflectionProperty::setRawValue</methodname></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
class Example
|
|
{
|
|
public int $age {
|
|
set {
|
|
if ($value <= 0) {
|
|
throw new \InvalidArgumentException();
|
|
}
|
|
$this->age = $value;
|
|
}
|
|
}
|
|
}
|
|
|
|
$example = new Example();
|
|
|
|
$rClass = new \ReflectionClass(Example::class);
|
|
$rProp = $rClass->getProperty('age');
|
|
|
|
// Ceci passerait par le hook set, et lancerait une exception.
|
|
$example->age = -2;
|
|
try {
|
|
$example->age = -2;
|
|
} catch (InvalidArgumentException) {
|
|
print "InvalidArgumentException for setting property to -2\n";
|
|
}
|
|
try {
|
|
$rProp->setValue($example, -2);
|
|
} catch (InvalidArgumentException) {
|
|
print "InvalidArgumentException for using ReflectionProperty::setValue() with -2\n";
|
|
}
|
|
|
|
// Mais cela définirait $age à -2 sans erreur.
|
|
$rProp->setRawValue($example, -2);
|
|
echo $example->age;
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
InvalidArgumentException for setting property to -2
|
|
InvalidArgumentException for using ReflectionProperty::setValue() with -2
|
|
-2
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<simplelist>
|
|
<member><link linkend="language.oop5.visibility-members-aviz">Visibilité de propriété asymétrique</link></member>
|
|
</simplelist>
|
|
</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
|
|
-->
|