svn: /phpdoc/ja/trunk/language/oop5/ basic.xml

[email protected] (Yoshinari Takaoka)
Newsgroups php.doc.ja
Message-ID <[email protected]>
mumumu                                   Sat, 28 Nov 2020 04:36:46 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=351717

Log:
Document the ::class constant on objects

Also, improve ::class description based on comments.

Closes GH-239.

Changed paths:
    U   phpdoc/ja/trunk/language/oop5/basic.xml

Modified: phpdoc/ja/trunk/language/oop5/basic.xml
===================================================================
--- phpdoc/ja/trunk/language/oop5/basic.xml	2020-11-28 04:24:52 UTC (rev 351716)
+++ phpdoc/ja/trunk/language/oop5/basic.xml	2020-11-28 04:36:46 UTC (rev 351717)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!-- $Revision$ -->
-<!-- EN-Revision: 350429 Maintainer: takagi Status: ready -->
+<!-- EN-Revision: 351711 Maintainer: takagi Status: ready -->
 <!-- CREDITS: hirokawa,mumumu -->

 <sect1 xml:id="language.oop5.basic" xmlns="http://docbook.org/ns/docbook">
@@ -415,7 +415,7 @@
    <title>::class</title>

    <para>
-    PHP 5.5 以降では、<literal>class</literal> キーワードでクラス名の解決ができるようになりました。
+    <literal>class</literal> キーワードでもクラス名の解決を行うことが出来ます。
     <literal>ClassName</literal> クラスの完全修飾名を文字列で取得するには、
     <literal>ClassName::class</literal> とします。
     これは、<link linkend="language.namespaces">
@@ -451,7 +451,50 @@
      結果的に、クラスがまだ存在しない時点でクラス名が展開されることになります。
      この場合にはエラーは発生しません。
     </para>
+    <example xml:id="language.oop5.basic.class.class.fail">
+     <title>クラス名が存在しない場合の名前解決</title>
+     <programlisting role="php">
+<![CDATA[
+<?php
+print Some\Class\DoesNot\Exist::class;
+?>
+]]>
+     </programlisting>
+     &example.outputs;
+     <screen>
+<![CDATA[
+Some\Class\Does\Not\Exist
+]]>
+     </screen>
+    </example>
    </note>
+   <para>
+    PHP 8.0.0 以降では、
+    <literal>::class</literal> はオブジェクトに対しても使えるようになりました。
+    この名前解決はコンパイル時ではなく、実行時に行われます。
+    この場合、<function>get_class</function> をオブジェクトに対して使った時と同じ動きをします。
+   </para>
+   <example xml:id="language.oop5.basic.class.class.object">
+    <title>オブジェクトの名前解決</title>
+    <programlisting role="php">
+<![CDATA[
+<?php
+namespace NS {
+    class ClassName {
+    }
+}
+$c = new ClassName();
+print $c::class;
+?>
+]]>
+    </programlisting>
+    &example.outputs;
+    <screen>
+<![CDATA[
+NS\ClassName
+]]>
+    </screen>
+   </example>
   </sect2>
  </sect1>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.