reference/reflection/reflectionproperty/setaccessible.xml
ec2fe9a592f794978114ef5021db9f1d00c2e05d
...
...
@@ -1,6 +1,5 @@
1
1
<?xml version="1.0" encoding="utf-8"?>
2
2
<!-- $Revision$ -->
3
-

4
3
<refentry xml:id="reflectionproperty.setaccessible" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
5
4
<refnamediv>
6
5
<refname>ReflectionProperty::setAccessible</refname>
...
...
@@ -9,14 +8,19 @@
9
8

10
9
<refsect1 role="description">
11
10
&reftitle.description;
12
-
<methodsynopsis>
11
+
<methodsynopsis role="ReflectionProperty">
13
12
<modifier>public</modifier> <type>void</type><methodname>ReflectionProperty::setAccessible</methodname>
14
13
<methodparam><type>bool</type><parameter>accessible</parameter></methodparam>
15
14
</methodsynopsis>
16
15
<para>
17
-
Sets a property to be accessible. For example, it may allow protected
18
-
and private properties to be accessed.
16
+
Enables access to a protected or private property via the <methodname>ReflectionProperty::getValue</methodname> and
17
+
<methodname>ReflectionProperty::setValue</methodname> methods.
19
18
</para>
19
+
<note>
20
+
<simpara>
21
+
As of PHP 8.1.0, calling this method has no effect; all properties are accessible by default.
22
+
</simpara>
23
+
</note>
20
24
</refsect1>
21
25

22
26
<refsect1 role="parameters">
...
...
@@ -42,6 +46,37 @@
42
46
</para>
43
47
</refsect1>
44
48

49
+
<refsect1 role="examples">
50
+
&reftitle.examples;
51
+
<example>
52
+
<title>Simple Class definition</title>
53
+
<programlisting role="php">
54
+
<![CDATA[
55
+
<?php
56
+
class MyClass
57
+
{
58
+
private $foo = 'bar';
59
+
}
60
+

61
+
$property = new ReflectionProperty("MyClass", "foo");
62
+
$property->setAccessible(true);
63
+

64
+
$obj = new MyClass();
65
+
echo $property->getValue($obj);
66
+
echo $obj->foo;
67
+
?>
68
+
]]>
69
+
</programlisting>
70
+
&example.outputs.similar;
71
+
<screen>
72
+
<![CDATA[
73
+
bar
74
+
Fatal error: Uncaught Error: Cannot access private property MyClass::$foo in /in/WJqTv:12
75
+
]]>
76
+
</screen>
77
+
</example>
78
+
</refsect1>
79
+

45
80
<refsect1 role="seealso">
46
81
&reftitle.seealso;
47
82
<para>
...
...
@@ -53,7 +88,6 @@
53
88
</refsect1>
54
89

55
90
</refentry>
56
-

57
91
<!-- Keep this comment at the end of the file
58
92
Local variables:
59
93
mode: sgml
60
94