1
0
mirror of https://github.com/php/doc-ru.git synced 2026-03-24 07:42:22 +01:00
Files
Mikhail Alferov f66b45a8ed Update Reflectionproperty to En (#1049)
* Update gethook.xml to en

* Update gethooks.xml to en

* Update getrawvalue.xml to en

* Update getsettabletype.xml to en

* Update hashook.xml to en

* Update hashooks.xml to en

* Update isfinal.xml to en

* Update isvirtual.xml to en

* Update setrawvalue.xml to en
2025-02-23 05:46:06 +03:00

145 lines
4.9 KiB
XML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: 49ef347a18b037370b6bd8e690096270f1780153 Maintainer: malferov Status: ready -->
<!-- Reviewed: no -->
<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>Устанавливает значение свойству в обход хука set, если такой хук определили</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>
Метод устанавливает значение свойству в обход хука <literal>set</literal>, если хук записи определили.
</simpara>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<variablelist>
<varlistentry>
<term><parameter>object</parameter></term>
<listitem>
<simpara>
Объект, свойству которого требуется установить значение.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>value</parameter></term>
<listitem>
<simpara>
Значение, которое требуется записать свойству. К допустимым относятся только те значения,
которые соответствуют типу свойства.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<simpara>
&return.void;
</simpara>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
<simpara>
При попытке установить значение виртуальному свойству метод выбросит ошибку <classname>Error</classname>,
поскольку движок PHP не предусматривает хранилище для значений виртуальных свойств.
</simpara>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example xml:id="reflectionproperty.setrawvalue.example.basic">
<title>Пример установки исходного значения свойству методом <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');
// Следующие попытки установить значение свойству пройдут через хук set и выбросят исключение
try {
$example->age = -2;
} catch (InvalidArgumentException) {
echo "При установке свойству значения -2 хук выбросил исключение InvalidArgumentException\n";
}
try {
$rProp->setValue($example, -2);
} catch (InvalidArgumentException) {
echo "При установке значения -2 методом ReflectionProperty::setValue() хук выбросил исключение InvalidArgumentException\n";
}
// Но такой вызов установит свойству $age значение -2 без ошибки
$rProp->setRawValue($example, -2);
echo $example->age;
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
При установке свойству значения -2 хук выбросил исключение InvalidArgumentException
При установке значения -2 методом ReflectionProperty::setValue() хук выбросил исключение InvalidArgumentException
-2
]]>
</screen>
</example>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<simplelist>
<member><link linkend="language.oop5.visibility-members-aviz">Асимметричная видимость свойств</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
-->