Improve get_debug_type() docs

Closes GH-591.
This commit is contained in:
markrandall 2021-05-09 21:50:18 +01:00 committed by GitHub
parent de8b838487
commit 51aee00be4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 213 additions and 1 deletions

View file

@ -0,0 +1,211 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="function.get-debug-type" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>get_debug_type</refname>
<refpurpose>Gets the type name of a variable in a way that is suitable for debugging</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>string</type><methodname>get_debug_type</methodname>
<methodparam><type>mixed</type><parameter>value</parameter></methodparam>
</methodsynopsis>
<para>
Returns the resolved name of the PHP variable <parameter>value</parameter>.
This function will resolve objects to their class name, resources to their
resource type name, and scalar values to their common name as would be used in type
declarations.
</para>
<para>
This function differs from <function>gettype</function> in that it returns type names
that are more consistent with actual usage, rather than those present for historical reasons.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>value</parameter></term>
<listitem>
<para>
The variable being type checked.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Possible values for the returned string are:
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>Type + State</entry>
<entry>Return Value</entry>
<entry>Notes</entry>
</row>
</thead>
<tbody>
<row>
<entry>null</entry>
<entry>
<literal>"null"</literal>
</entry>
<entry>-</entry>
</row>
<row>
<entry>Booleans (true or false)</entry>
<entry>
<literal>"bool"</literal>
</entry>
<entry>-</entry>
</row>
<row>
<entry>Integers</entry>
<entry>
<literal>"int"</literal>
</entry>
<entry>-</entry>
</row>
<row>
<entry>Floats</entry>
<entry>
<literal>"float"</literal>
</entry>
<entry>-</entry>
</row>
<row>
<entry>Strings</entry>
<entry>
<literal>"string"</literal>
</entry>
<entry>-</entry>
</row>
<row>
<entry>Arrays</entry>
<entry>
<literal>"array"</literal>
</entry>
<entry>-</entry>
</row>
<row>
<entry>Resources</entry>
<entry>
<literal>"resource (resourcename)"</literal>
</entry>
<entry>-</entry>
</row>
<row>
<entry>Resources (Closed)</entry>
<entry>
<literal>"resource (closed)"</literal>
</entry>
<entry>Example: A file stream after being closed with fclose.</entry>
</row>
<row>
<entry>Objects from Named Classes</entry>
<entry>
The full name of the class including its namespace e.g. <literal>Foo\Bar</literal>
</entry>
<entry>-</entry>
</row>
<row>
<entry>Objects from Anonymous Classes</entry>
<entry>
<literal>"class@anonymous"</literal>
</entry>
<entry>
Anonymous classes are those created through the $x = new class { ... } syntax
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>gettype</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
echo get_debug_type(null) . PHP_EOL;
echo get_debug_type(true) . PHP_EOL;
echo get_debug_type(1) . PHP_EOL;
echo get_debug_type(0.1) . PHP_EOL;
echo get_debug_type("foo") . PHP_EOL;
echo get_debug_type([]) . PHP_EOL;
$fp = fopen(__FILE__, 'rb');
echo get_debug_type($fp) . PHP_EOL;
fclose($fp);
echo get_debug_type($fp) . PHP_EOL;
echo get_debug_type(new stdClass) . PHP_EOL;
echo get_debug_type(new class {}) . PHP_EOL;
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
null
bool
int
float
string
array
resource (stream)
resource (closed)
stdClass
class@anonymous
]]>
</screen>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>gettype</function></member>
<member><function>get_class</function></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->

View file

@ -90,7 +90,7 @@
<row>
<entry>7.2.0</entry>
<entry>
Closed resources are now reported as <literal>'resource (closed)'</literal>.
Closed resources are now reported as <literal>'resource (closed)'</literal>.
Previously the returned value for closed resources were <literal>'unknown type'</literal>.
</entry>
</row>
@ -136,6 +136,7 @@ string
&reftitle.seealso;
<para>
<simplelist>
<member><function>get_debug_type</function></member>
<member><function>settype</function></member>
<member><function>get_class</function></member>
<member><function>is_array</function></member>