com doc/fr: Apply commit cc422ba8c722072aeaeaf36b03eb660e05e11d02: reference/reflection/reflectionmethod/setaccessible.xml reference/reflection/reflectionproperty/setaccessible.xml
[email protected] (George Peter Banyard) Wed, 13 Jan 2021 04:09:56 +0000
| Newsgroups | php.doc.fr |
|---|---|
| Message-ID | <[email protected]> |
Commit: ad823568f6466b4fb458511b9b764005299753b8 Author: George Peter Banyard <[email protected]> Wed, 13 Jan 2021 04:09:56 +0000 Parents: bc3357a2048c0c076795b09e1b94262470a5d7eb Branches: master Link: http://git.php.net/?p=doc/fr.git;a=commitdiff;h=ad823568f6466b4fb458511b9b764005299753b8 Log: Apply commit cc422ba8c722072aeaeaf36b03eb660e05e11d02 Fix #55026: Document access to protected/private members using reflection Bugs: https://bugs.php.net/55026 Changed paths: M reference/reflection/reflectionmethod/setaccessible.xml M reference/reflection/reflectionproperty/setaccessible.xml Diff: diff --git a/reference/reflection/reflectionmethod/setaccessible.xml b/reference/reflection/reflectionmethod/setaccessible.xml index 9fc1f3319f..f2ac75ed39 100644 --- a/reference/reflection/reflectionmethod/setaccessible.xml +++ b/reference/reflection/reflectionmethod/setaccessible.xml @@ -1,8 +1,7 @@ <?xml version="1.0" encoding="utf-8"?> <!-- $Revision$ --> -<!-- EN-Revision: b71e8b802f19ebed1067898d628e8a03b0550a11 Maintainer: yannick Status: ready --> +<!-- EN-Revision: cc422ba8c722072aeaeaf36b03eb660e05e11d02 Maintainer: yannick Status: ready --> <!-- Reviewed: no --> - <refentry xml:id="reflectionmethod.setaccessible" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"> <refnamediv> <refname>ReflectionMethod::setAccessible</refname> @@ -16,8 +15,8 @@ <methodparam><type>bool</type><parameter>accessible</parameter></methodparam> </methodsynopsis> <para> - Définit l'accessibilité de la méthode. Par exemple, ceci permet - d'invoquer des méthodes protégées et privées. + Active l'invocation des méthodes protégées et privées via la méthode + <methodname>ReflectionMethod::invoke</methodname>. </para> </refsect1> @@ -44,6 +43,38 @@ </para> </refsect1> + <refsect1 role="examples"> + &reftitle.examples; + <example> + <title>Définition d'une classe simple</title> + <programlisting role="php"> +<![CDATA[ +<?php +class MyClass +{ + private function foo() + { + return 'bar'; + } +} +$method = new ReflectionMethod("MyClass", "foo"); +$method->setAccessible(true); +$obj = new MyClass(); +echo $method->invoke($obj); +echo $obj->foo(); +?> +]]> + </programlisting> + &example.outputs.similar; + <screen> +<![CDATA[ +bar +Fatal error: Uncaught Error: Call to private method MyClass::foo() from global scope in /in/qdaZS:16 +]]> + </screen> + </example> + </refsect1> + <refsect1 role="seealso"> &reftitle.seealso; <para> diff --git a/reference/reflection/reflectionproperty/setaccessible.xml b/reference/reflection/reflectionproperty/setaccessible.xml index cb3c0cf6dd..dce9e1e15d 100644 --- a/reference/reflection/reflectionproperty/setaccessible.xml +++ b/reference/reflection/reflectionproperty/setaccessible.xml @@ -1,8 +1,7 @@ <?xml version="1.0" encoding="utf-8"?> <!-- $Revision$ --> -<!-- EN-Revision: b71e8b802f19ebed1067898d628e8a03b0550a11 Maintainer: yannick Status: ready --> -<!-- Reviewed: yes --> - +<!-- EN-Revision: cc422ba8c722072aeaeaf36b03eb660e05e11d02 Maintainer: yannick Status: ready --> +<!-- Reviewed: no --> <refentry xml:id="reflectionproperty.setaccessible" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"> <refnamediv> <refname>ReflectionProperty::setAccessible</refname> @@ -16,8 +15,9 @@ <methodparam><type>bool</type><parameter>accessible</parameter></methodparam> </methodsynopsis> <para> - Définit l'accessibilité d'une propriété. - Par exemple, ceci permet de rendre accessible une propriété protégée ou privée. + Active l'accès à une propriété protégée ou privée via les méthodes + <methodname>ReflectionProperty::getValue</methodname> et + <methodname>ReflectionProperty::setValue</methodname>. </para> </refsect1> @@ -44,6 +44,35 @@ </para> </refsect1> + <refsect1 role="examples"> + &reftitle.examples; + <example> + <title>Définition d'une classe simple</title> + <programlisting role="php"> +<![CDATA[ +<?php +class MyClass +{ + private $foo = 'bar'; +} +$property = new ReflectionProperty("MyClass", "foo"); +$property->setAccessible(true); +$obj = new MyClass(); +echo $property->getValue($obj); +echo $obj->foo; +?> +]]> + </programlisting> + &example.outputs.similar; + <screen> +<![CDATA[ +bar +Fatal error: Uncaught Error: Cannot access private property MyClass::$foo in /in/WJqTv:12 +]]> + </screen> + </example> + </refsect1> + <refsect1 role="seealso"> &reftitle.seealso; <para>