com doc/zh: 更新 gettype(): reference/v ar/functions/gettype.xml

From: Date: Sat, 20 Feb 2021 08:45:38 +0000
Subject: com doc/zh: 更新 gettype(): reference/v ar/functions/gettype.xml
Groups: php.doc.zh 
Request: Send a blank email to doc-zh+get-5982@lists.php.net to get a copy of this message
Commit: 2999bfaef397e16a60b3971069a62774f09eae30 Author: 蒋文健 <jwjbjg@gmail.com> Sat, 20 Feb 2021 13:47:43 +0800 Committer: Bole Chen <avenger@php.net> Sat, 20 Feb 2021 16:45:38 +0800 Parents: 9c2a89b9b90a9fe36ff8050392fd76aea88466ff Branches: master Link: http://git.php.net/?p=doc/zh.git;a=commitdiff;h=2999bfaef397e16a60b3971069a62774f09eae30 Log: 更新 gettype() Changed paths: M reference/var/functions/gettype.xml Diff: diff --git a/reference/var/functions/gettype.xml b/reference/var/functions/gettype.xml index 201ce656..2ffd096a 100644 --- a/reference/var/functions/gettype.xml +++ b/reference/var/functions/gettype.xml @@ -1,82 +1,161 @@ <?xml version="1.0" encoding="utf-8"?> <!-- $Revision$ --> <!-- $Author$ --> -<!-- EN-Revision: n/a Maintainer: nio Status: ready --> -<!-- splitted from ./en/functions/var.xml, last change in rev 1.2 --> - <refentry xml:id="function.gettype" xmlns="http://docbook.org/ns/docbook"> - <refnamediv> - <refname>gettype</refname> - <refpurpose>获取变量的类型</refpurpose> - </refnamediv> - <refsect1> - <title>描述</title> - <methodsynopsis> - <type>string</type><methodname>gettype</methodname> - <methodparam><type>mixed</type><parameter>var</parameter></methodparam> - </methodsynopsis> - <para> - 返回 PHP 变量的类型 - <parameter>var</parameter>. - </para> - <warning> - <simpara> - 不要使用 <function>gettype</function> - 来测试某种类型,因为其返回的字符串在未来的版本中可能需要改变。此外,由于包含了字符串的比较,它的运行也是较慢的。 - <!-- where's my dictionary? --> - </simpara> - <simpara> - 使用 <literal>is_*</literal> 函数代替。 - </simpara> - </warning> - <para> - 返回的字符串的可能值为: - <itemizedlist> - <listitem> - <simpara>“<type>boolean</type>”(从 PHP 4 起)</simpara> - </listitem> - <listitem> - <simpara>“<type>integer</type>”</simpara> - </listitem> - <listitem> - <simpara>“<type>double</type>”(由于历史原因,如果是 <type>float</type> 则返回“double”,而不是“float”)</simpara> - </listitem> - <listitem> - <simpara>“<type>string</type>”</simpara> - </listitem> - <listitem> - <simpara>“<type>array</type>”</simpara> - </listitem> - <listitem> - <simpara>“<type>object</type>”</simpara> - </listitem> - <listitem> - <simpara>“<type>resource</type>”(从 PHP 4 起)</simpara> - </listitem> - <listitem> - <simpara>“<type>NULL</type>”(从 PHP 4 起)</simpara> - </listitem> - <listitem> - <simpara>“user function”(只用于 PHP 3,现已停用)</simpara> - </listitem> - <listitem> - <simpara>“unknown type”<!-- someone's joking? --></simpara> - </listitem> - </itemizedlist> - </para> - <para> - 对于 PHP 4,你应该使用 <function>function_exists</function> - 和 <function>method_exists</function> - 取代先前将 <function>gettype</function> - 作用于函数的用法。 - </para> - <para> - 参见 - <function>settype</function>、<function>is_array</function>、<function>is_bool</function>、<function>is_float</function>、<function>is_integer</function>、<function>is_null</function>、<function>is_numeric</function>、<function>is_object</function>、<function>is_resource</function>、<function>is_scalar</function> - 和 <function>is_string</function>。 - </para> - </refsect1> - </refentry> +<!-- EN-Revision: 0c9c2dd669fe9395eaa73d487fbd160f9057429a Maintainer: nio Status: ready --> +<refentry xml:id="function.gettype" xmlns="http://docbook.org/ns/docbook"> + <refnamediv> + <refname>gettype</refname> + <refpurpose>获取变量的类型</refpurpose> + </refnamediv> + <refsect1 role="description"> + &reftitle.description; + <methodsynopsis> + <type>string</type><methodname>gettype</methodname> + <methodparam><type>mixed</type><parameter>value</parameter></methodparam> + </methodsynopsis> + <para> + 返回 PHP <parameter>value</parameter> 变量的类型。 + 对于类型检查,请使用 <literal>is_*</literal> 函数。 + </para> + </refsect1> + + <refsect1 role="parameters"> + &reftitle.parameters; + <para> + <variablelist> + <varlistentry> + <term><parameter>value</parameter></term> + <listitem> + <para> + 要检查类型的变量。 + </para> + </listitem> + </varlistentry> + </variablelist> + </para> + </refsect1> + + <refsect1 role="returnvalues"> + &reftitle.returnvalues; + <para> + 返回字符串,可能值为: + <simplelist> + <member> + <literal>"boolean"</literal> + </member> + <member> + <literal>"integer"</literal> + </member> + <member> + <literal>"double"</literal> + (由于历史原因,如果是浮点型,则返回 <literal>"double"</literal>,而不仅仅是 <literal>"float"</literal>) + </member> + <member> + <literal>"string"</literal> + </member> + <member> + <literal>"array"</literal> + </member> + <member> + <literal>"object"</literal> + </member> + <member> + <literal>"resource"</literal> + </member> + <member> + <literal>"resource (closed)"</literal> 自 PHP 7.2.0 起 + </member> + <member> + <literal>"NULL"</literal> + </member> + <member> + <literal>"unknown type"</literal> + </member> + </simplelist> + </para> + </refsect1> + + <refsect1 role="examples"> + &reftitle.examples; + <para> + <example> + <title><function>gettype</function> 示例</title> + <programlisting role="php"> +<![CDATA[ +<?php + +$data = array(1, 1., NULL, new stdClass, 'foo'); + +foreach ($data as $value) { + echo gettype($value), "\n"; +} + +?> +]]> + </programlisting> + &example.outputs.similar; + <screen> +<![CDATA[ +integer +double +NULL +object +string +]]> + </screen> + </example> + </para> + </refsect1> + + <refsect1 role="changelog"> + &reftitle.changelog; + <para> + <informaltable> + <tgroup cols="2"> + <thead> + <row> + <entry>&Version;</entry> + <entry>&Description;</entry> + </row> + </thead> + <tbody> + <row> + <entry>7.2.0</entry> + <entry> + 现在,已关闭的资源报告为 <literal>'resource (closed)'</literal>。 + 此前,已关闭的资源报告为 <literal>'unknown type'</literal>。 + </entry> + </row> + </tbody> + </tgroup> + </informaltable> + </para> + </refsect1> + + <refsect1 role="seealso"> + &reftitle.seealso; + <para> + <simplelist> + <member><function>settype</function></member> + <member><function>get_class</function></member> + <member><function>is_array</function></member> + <member><function>is_bool</function></member> + <member><function>is_callable</function></member> + <member><function>is_float</function></member> + <member><function>is_int</function></member> + <member><function>is_null</function></member> + <member><function>is_numeric</function></member> + <member><function>is_object</function></member> + <member><function>is_resource</function></member> + <member><function>is_scalar</function></member> + <member><function>is_string</function></member> + <member><function>function_exists</function></member> + <member><function>method_exists</function></member> + </simplelist> + </para> + </refsect1> +</refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml

« previous php.doc.zh (#5982) next »