language/oop5/static.xml
3c831023489be0c64268882d5b656149140d6f8b
...
...
@@ -8,7 +8,8 @@
8
8
This page describes the use of the <literal>static</literal> keyword to
9
9
define static methods and properties. <literal>static</literal> can also
10
10
be used to
11
-
<link linkend="language.variables.scope.static">define static variables</link>
11
+
<link linkend="language.variables.scope.static">define static variables</link>,
12
+
<link linkend="functions.anonymous-functions.static">define static anonymous functions</link>
12
13
and for
13
14
<link linkend="language.oop5.late-static-bindings">late static bindings</link>.
14
15
Please refer to those pages for information on those meanings of
...
...
@@ -18,9 +19,8 @@
18
19

19
20
<para>
20
21
Declaring class properties or methods as static makes them accessible
21
-
without needing an instantiation of the class. A property declared as
22
-
static cannot be accessed with an instantiated class object (though
23
-
a static method can).
22
+
without needing an instantiation of the class.
23
+
These can also be accessed statically within an instantiated class object.
24
24
</para>
25
25

26
26
<sect2 xml:id="language.oop5.static.methods">
...
...
@@ -29,7 +29,7 @@
29
29
<para>
30
30
Because static methods are callable without an instance of
31
31
the object created, the pseudo-variable <varname>$this</varname> is
32
-
not available inside the method declared as static.
32
+
not available inside methods declared as static.
33
33
</para>
34
34

35
35
<warning>
...
...
@@ -37,8 +37,8 @@
37
37
Calling non-static methods statically throws an <classname>Error</classname>.
38
38
</para>
39
39
<para>
40
-
Prior to PHP 8.0.0, calling non-static methods statically is deprecated, and will
41
-
generate an <constant>E_DEPRECATED</constant> warning.
40
+
Prior to PHP 8.0.0, calling non-static methods statically were deprecated, and
41
+
generated an <constant>E_DEPRECATED</constant> warning.
42
42
</para>
43
43
</warning>
44
44

...
...
@@ -66,15 +66,10 @@ $classname::aStaticMethod();
66
66
<title>Static properties</title>
67
67

68
68
<para>
69
-
Static properties cannot be accessed through the object using the arrow
70
-
operator -&gt;.
71
-
</para>
72
-

73
-
<para>
74
-
Like any other PHP static variable, static properties may be
75
-
initialized with the same rules apply as &const;
76
-
expressions: some limited expressions are possible, provided they can be
77
-
evaluated at compile time.
69
+
Static properties are accessed using the
70
+
<link linkend="language.oop5.paamayim-nekudotayim">Scope Resolution Operator</link>
71
+
(<literal>::</literal>) and cannot be accessed through the object operator
72
+
(<literal>-&gt;</literal>).
78
73
</para>
79
74

80
75
<para>
...
...
@@ -121,6 +116,22 @@ print $bar->fooStatic() . "\n";
121
116
?>
122
117
]]>
123
118
</programlisting>
119
+
&example.outputs.8.similar;
120
+
<screen>
121
+
<![CDATA[
122
+
foo
123
+
foo
124
+

125
+
Notice: Accessing static property Foo::$my_static as non static in /in/V0Rvv on line 23
126
+

127
+
Warning: Undefined property: Foo::$my_static in /in/V0Rvv on line 23
128
+

129
+
foo
130
+
foo
131
+
foo
132
+
foo
133
+
]]>
134
+
</screen>
124
135
</example>
125
136
</sect2>
126
137
</sect1>
127
138