reference/reflection/reflectionmethod/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="reflectionmethod.setaccessible" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
5
4
<refnamediv>
6
5
<refname>ReflectionMethod::setAccessible</refname>
...
...
@@ -9,14 +8,18 @@
9
8

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

22
25
<refsect1 role="parameters">
...
...
@@ -42,6 +45,40 @@
42
45
</para>
43
46
</refsect1>
44
47

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

63
+
$method = new ReflectionMethod("MyClass", "foo");
64
+
$method->setAccessible(true);
65
+

66
+
$obj = new MyClass();
67
+
echo $method->invoke($obj);
68
+
echo $obj->foo();
69
+
?>
70
+
]]>
71
+
</programlisting>
72
+
&example.outputs.similar;
73
+
<screen>
74
+
<![CDATA[
75
+
bar
76
+
Fatal error: Uncaught Error: Call to private method MyClass::foo() from global scope in /in/qdaZS:16
77
+
]]>
78
+
</screen>
79
+
</example>
80
+
</refsect1>
81
+

45
82
<refsect1 role="seealso">
46
83
&reftitle.seealso;
47
84
<para>
...
...
@@ -52,7 +89,6 @@
52
89
</para>
53
90
</refsect1>
54
91
</refentry>
55
-

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