|
| 1 | +<?xml version="1.0" encoding="utf-8"?> |
| 2 | +<!-- $Revision$ --> |
| 3 | +<!-- EN-Revision: c0e48705eb88453af785e0e4a6cbd526085dfe3a Maintainer: Luffy Status: ready --> |
| 4 | +<reference xml:id="class.php-incomplete-class" role="class" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude"> |
| 5 | + |
| 6 | + <title>__PHP_Incomplete_Class 类</title> |
| 7 | + <titleabbrev>__PHP_Incomplete_Class</titleabbrev> |
| 8 | + |
| 9 | + <partintro> |
| 10 | + |
| 11 | + <section xml:id="php-incomplete-class.intro"> |
| 12 | + &reftitle.intro; |
| 13 | + <para> |
| 14 | + 由 <function>unserialize</function> 创建的在尝试反序列化未定义类或未在 <function>unserialize</function> |
| 15 | + 的 <parameter>options</parameter> 数组的 <literal>allowed_classes</literal> |
| 16 | + 中列出的类。 |
| 17 | + </para> |
| 18 | + |
| 19 | + <para> |
| 20 | + 在 PHP 7.2.0 之前,对 <classname>__PHP_Incomplete_Class</classname> 类使用 <function>is_object</function> |
| 21 | + 会返回 &false;。从 PHP 7.2.0 开始,将返回 &true;。 |
| 22 | + </para> |
| 23 | + </section> |
| 24 | + |
| 25 | + <section xml:id="php-incomplete-class.synopsis"> |
| 26 | + &reftitle.classsynopsis; |
| 27 | + |
| 28 | + <classsynopsis class="class"> |
| 29 | + <ooclass> |
| 30 | + <modifier>final</modifier> |
| 31 | + <classname>__PHP_Incomplete_Class</classname> |
| 32 | + </ooclass> |
| 33 | + </classsynopsis> |
| 34 | + |
| 35 | + <para> |
| 36 | + 此类没有默认属性或方法。 |
| 37 | + 由 <function>unserialize</function> 创建时, |
| 38 | + 除了所有反序列化的属性和值之外, |
| 39 | + 对象还将具有一个 <literal>__PHP_Incomplete_Class_Name</literal> 属性, |
| 40 | + 该属性将包含反序列化类的名称。 |
| 41 | + </para> |
| 42 | + </section> |
| 43 | + |
| 44 | + <section xml:id="php-incomplete-class.changelog" role="changelog"> |
| 45 | + &reftitle.changelog; |
| 46 | + <informaltable> |
| 47 | + <tgroup cols="2"> |
| 48 | + <thead> |
| 49 | + <row> |
| 50 | + <entry>&Version;</entry> |
| 51 | + <entry>&Description;</entry> |
| 52 | + </row> |
| 53 | + </thead> |
| 54 | + <tbody> |
| 55 | + <row> |
| 56 | + <entry>8.0.0</entry> |
| 57 | + <entry> |
| 58 | + 此类现在是 <literal>final</literal>。 |
| 59 | + </entry> |
| 60 | + </row> |
| 61 | + </tbody> |
| 62 | + </tgroup> |
| 63 | + </informaltable> |
| 64 | + </section> |
| 65 | + |
| 66 | + <section xml:id="php-incomplete-class.examples" role="examples"> |
| 67 | + &reftitle.examples; |
| 68 | + <example xml:id="php-incomplete-class.basic-example"> |
| 69 | + <title>由 <function>unserialize</function> 创建</title> |
| 70 | + <programlisting role="php"> |
| 71 | +<![CDATA[ |
| 72 | +<?php |
| 73 | +
|
| 74 | +class MyClass |
| 75 | +{ |
| 76 | + public string $property = "myValue"; |
| 77 | +} |
| 78 | +
|
| 79 | +$myObject = new MyClass; |
| 80 | +
|
| 81 | +$foo = serialize($myObject); |
| 82 | +
|
| 83 | +// unserializes all objects into __PHP_Incomplete_Class objects |
| 84 | +$disallowed = unserialize($foo, ["allowed_classes" => false]); |
| 85 | +
|
| 86 | +var_dump($disallowed); |
| 87 | +
|
| 88 | +// unserializes all objects into __PHP_Incomplete_Class objects except those of MyClass2 and MyClass3 |
| 89 | +$disallowed2 = unserialize($foo, ["allowed_classes" => ["MyClass2", "MyClass3"]]); |
| 90 | +
|
| 91 | +var_dump($disallowed2); |
| 92 | +
|
| 93 | +// unserializes undefined class into __PHP_Incomplete_Class object |
| 94 | +$undefinedClass = unserialize('O:16:"MyUndefinedClass":0:{}'); |
| 95 | +
|
| 96 | +var_dump($undefinedClass); |
| 97 | +]]> |
| 98 | + </programlisting> |
| 99 | + &example.outputs; |
| 100 | + <screen> |
| 101 | +<![CDATA[ |
| 102 | +
|
| 103 | +object(__PHP_Incomplete_Class)#2 (2) { |
| 104 | + ["__PHP_Incomplete_Class_Name"]=> |
| 105 | + string(7) "MyClass" |
| 106 | + ["property"]=> |
| 107 | + string(7) "myValue" |
| 108 | +} |
| 109 | +object(__PHP_Incomplete_Class)#3 (2) { |
| 110 | + ["__PHP_Incomplete_Class_Name"]=> |
| 111 | + string(7) "MyClass" |
| 112 | + ["property"]=> |
| 113 | + string(7) "myValue" |
| 114 | +} |
| 115 | +object(__PHP_Incomplete_Class)#4 (1) { |
| 116 | + ["__PHP_Incomplete_Class_Name"]=> |
| 117 | + string(16) "MyUndefinedClass" |
| 118 | +} |
| 119 | +
|
| 120 | +]]> |
| 121 | + </screen> |
| 122 | + </example> |
| 123 | + </section> |
| 124 | + |
| 125 | + </partintro> |
| 126 | + |
| 127 | +</reference> |
| 128 | +<!-- Keep this comment at the end of the file |
| 129 | +Local variables: |
| 130 | +mode: sgml |
| 131 | +sgml-omittag:t |
| 132 | +sgml-shorttag:t |
| 133 | +sgml-minimize-attributes:nil |
| 134 | +sgml-always-quote-attributes:t |
| 135 | +sgml-indent-step:1 |
| 136 | +sgml-indent-data:t |
| 137 | +indent-tabs-mode:nil |
| 138 | +sgml-parent-document:nil |
| 139 | +sgml-default-dtd-file:"~/.phpdoc/manual.ced" |
| 140 | +sgml-exposed-tags:nil |
| 141 | +sgml-local-catalogs:nil |
| 142 | +sgml-local-ecat-files:nil |
| 143 | +End: |
| 144 | +vim600: syn=xml fen fdm=syntax fdl=2 si |
| 145 | +vim: et tw=78 syn=sgml |
| 146 | +vi: ts=1 sw=1 |
| 147 | +--> |
0 commit comments