reference/classobj/functions/get-class.xml
4f36c26a72c40b16e955c3c1c88041910932d0bf
...
...
@@ -9,7 +9,7 @@
9
9
&reftitle.description;
10
10
<methodsynopsis>
11
11
<type>string</type><methodname>get_class</methodname>
12
-
<methodparam choice="opt"><type>object</type><parameter>object</parameter><initializer>&null;</initializer></methodparam>
12
+
<methodparam choice="opt"><type>object</type><parameter>object</parameter></methodparam>
13
13
</methodsynopsis>
14
14
<para>
15
15
Gets the name of the class of the given <parameter>object</parameter>.
...
...
@@ -23,8 +23,16 @@
23
23
<term><parameter>object</parameter></term>
24
24
<listitem>
25
25
<para>
26
-
The tested object. This parameter may be omitted when inside a class.
26
+
The tested object.
27
27
</para>
28
+
<note>
29
+
<simpara>
30
+
Explicitly passing &null; as the <parameter>object</parameter> is no
31
+
longer allowed as of PHP 7.2.0 and emits an <constant>E_WARNING</constant>.
32
+
As of PHP 8.0.0, a <classname>TypeError</classname> is emitted when
33
+
&null; is used.
34
+
</simpara>
35
+
</note>
28
36
</listitem>
29
37
</varlistentry>
30
38
</variablelist>
...
...
@@ -34,19 +42,24 @@
34
42
&reftitle.returnvalues;
35
43
<para>
36
44
Returns the name of the class of which <parameter>object</parameter> is an
37
-
instance. Returns &false; if <parameter>object</parameter> is not an
38
-
object.
45
+
instance.
39
46
</para>
40
47
<para>
41
-
If <parameter>object</parameter> is omitted when inside a class, the
42
-
name of that class is returned.
48
+
If the <parameter>object</parameter> is an instance of a class which exists
49
+
in a namespace, the qualified namespaced name of that class is returned.
43
50
</para>
44
51
</refsect1>
45
52
<refsect1 role="errors">
46
53
&reftitle.errors;
47
54
<para>
48
55
If <function>get_class</function> is called with anything other than an
49
-
object, an <constant>E_WARNING</constant> level error is raised.
56
+
object, <classname>TypeError</classname> is raised. Prior to PHP 8.0.0,
57
+
an <constant>E_WARNING</constant> level error was raised.
58
+
</para>
59
+
<para>
60
+
If <function>get_class</function> is called with no arguments from outside a class,
61
+
an <classname>Error</classname> is thrown. Prior to PHP 8.0.0,
62
+
an <constant>E_WARNING</constant> level error was raised.
50
63
</para>
51
64
</refsect1>
52
65
<refsect1 role="changelog">
...
...
@@ -62,11 +75,29 @@
62
75
</thead>
63
76
<tbody>
64
77
<row>
65
-
<entry>5.3.0</entry>
78
+
<entry>8.3.0</entry>
79
+
<entry>
80
+
Calling <function>get_class</function> without an argument now emits an
81
+
<constant>E_DEPRECATED</constant> warning;
82
+
previously, calling this function inside a class returned the name of that class.
83
+
</entry>
84
+
</row>
85
+
<row>
86
+
<entry>8.0.0</entry>
87
+
<entry>
88
+
Calling this function from outside a class, without any arguments,
89
+
will now throw an <classname>Error</classname>.
90
+
Previously, an <constant>E_WARNING</constant> was raised
91
+
and the function returned &false;.
92
+
</entry>
93
+
</row>
94
+
<row>
95
+
<entry>7.2.0</entry>
66
96
<entry>
67
-
&null; became the default value for <parameter>object</parameter>,
68
-
so passing &null; to <parameter>object</parameter> now has the same
69
-
result as not passing any value.
97
+
Prior to this version the default value for <parameter>object</parameter>
98
+
was &null; and it had the same effect as not passing any value. Now
99
+
&null; has been removed as the default value for <parameter>object</parameter>,
100
+
and is no longer a valid input.
70
101
</entry>
71
102
</row>
72
103
</tbody>
...
...
@@ -140,6 +171,34 @@ string(3) "bar"
140
171
]]>
141
172
</screen>
142
173
</example>
174
+
<example>
175
+
<title>Using <function>get_class</function> with namespaced classes</title>
176
+
<programlisting role="php">
177
+
<![CDATA[
178
+
<?php
179
+

180
+
namespace Foo\Bar;
181
+

182
+
class Baz {
183
+
public function __construct()
184
+
{
185
+

186
+
}
187
+
}
188
+

189
+
$baz = new \Foo\Bar\Baz;
190
+

191
+
var_dump(get_class($baz));
192
+
?>
193
+
]]>
194
+
</programlisting>
195
+
&example.outputs;
196
+
<screen>
197
+
<![CDATA[
198
+
string(11) "Foo\Bar\Baz"
199
+
]]>
200
+
</screen>
201
+
</example>
143
202
</para>
144
203
</refsect1>
145
204
<refsect1 role="seealso">
...
...
@@ -149,6 +208,7 @@ string(3) "bar"
149
208
<member><function>get_called_class</function></member>
150
209
<member><function>get_parent_class</function></member>
151
210
<member><function>gettype</function></member>
211
+
<member><function>get_debug_type</function></member>
152
212
<member><function>is_subclass_of</function></member>
153
213
</simplelist>
154
214
</para>
155
215