Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 63 additions & 42 deletions reference/dir/functions/closedir.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- splitted from ./en/functions/dir.xml, last change in rev 1.2 -->
<refentry xml:id="function.closedir" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>closedir</refname>
Expand All @@ -13,61 +11,84 @@
<type>void</type><methodname>closedir</methodname>
<methodparam choice="opt"><type class="union"><type>resource</type><type>null</type></type><parameter>dir_handle</parameter><initializer>&null;</initializer></methodparam>
</methodsynopsis>
<para>
<simpara>
Closes the directory stream indicated by
<parameter>dir_handle</parameter>. The stream must have previously
been opened by <function>opendir</function>.
</para>
<parameter>dir_handle</parameter>.
</simpara>
</refsect1>

<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>dir_handle</parameter></term>
<listitem>
<para>
The directory handle <type>resource</type> previously opened
with <function>opendir</function>. If the directory handle is
not specified, the last link opened by <function>opendir</function>
is assumed.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
<variablelist>
<varlistentry>
<term><parameter>dir_handle</parameter></term>
<listitem>
<simpara>
A directory handle <type>resource</type> previously opened
with <function>opendir</function>.
If <parameter>dir_handle</parameter> is &null; the last handle opened
using <function>opendir</function> will be used.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</refsect1>

<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
<simpara>
&return.void;
</para>
</simpara>
</refsect1>

<refsect1 role="changelog">
&reftitle.changelog;
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>8.5.0</entry>
<entry>
Using &null; for <parameter>dir_handle</parameter> is now deprecated.
Instead, the last opened directory handle should be explicitly provided.
</entry>
</row>
<row>
<entry>8.0.0</entry>
<entry>
<parameter>dir_handle</parameter> is now nullable.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</refsect1>

<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>closedir</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
$dir = "/etc/php5/";
<simpara>
For a complete example refer to the <function>opendir</function>
documentation.
</simpara>
</refsect1>

// Open a known directory, read directory into variable and then close
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
$directory = readdir($dh);
closedir($dh);
}
}
?>
]]>
</programlisting>
</example>
</para>
<refsect1 role="seealso">
&reftitle.seealso;
<simplelist>
<member><function>opendir</function></member>
<member><function>readdir</function></member>
<member><function>rewinddir</function></member>
<member><function>dir</function></member>
<member><function>is_dir</function></member>
<member><function>glob</function></member>
<member><function>scandir</function></member>
</simplelist>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Expand Down
122 changes: 67 additions & 55 deletions reference/dir/functions/opendir.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- splitted from ./en/functions/dir.xml, last change in rev 1.2 -->
<refentry xml:id="function.opendir" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>opendir</refname>
Expand All @@ -14,55 +12,53 @@
<methodparam><type>string</type><parameter>directory</parameter></methodparam>
<methodparam choice="opt"><type class="union"><type>resource</type><type>null</type></type><parameter>context</parameter><initializer>&null;</initializer></methodparam>
</methodsynopsis>
<para>
<simpara>
Opens up a directory handle to be used in subsequent
<function>closedir</function>, <function>readdir</function>, and
<function>rewinddir</function> calls.
</para>
</simpara>
</refsect1>

<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>directory</parameter></term>
<listitem>
<para>
The directory path that is to be opened
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>context</parameter></term>
<listitem>
<para>
For a description of the <parameter>context</parameter> parameter,
refer to <link linkend="ref.stream">the streams section</link> of
the manual.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
<variablelist>
<varlistentry>
<term><parameter>directory</parameter></term>
<listitem>
<simpara>
The directory path to open.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>context</parameter></term>
<listitem>
<simpara>
For a description of the <parameter>context</parameter> parameter,
refer to <link linkend="ref.stream">the streams section</link> of
the manual.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</refsect1>

<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns a directory handle <type>resource</type> on success,
<simpara>
Returns a directory handle on success,
&return.falseforfailure;
</para>
</simpara>
</refsect1>

<refsect1 role="errors">
&reftitle.errors;
&fs.emits.warning.on.failure;
<para>
<simpara>
This may happen if <parameter>directory</parameter> is not a valid directory,
the directory can not be opened due to permission restrictions,
or due to filesystem errors.
</para>
</simpara>
</refsect1>

<refsect1 role="changelog">
Expand All @@ -89,49 +85,65 @@

<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>opendir</function> example</title>
<programlisting role="php">
<example>
<title>
List all entries in a directory, skipping the special <literal>.</literal>
and <literal>..</literal> directories
</title>
<simpara>
Because file and directory names can be strings that PHP considers "falsy"
(e.g. a directory named <literal>"0"</literal>) and
<function>readdir</function> returns &false; when it has read all entries
in a directory one needs to use the <literal>===</literal>
<link linkend="language.operators.comparison">comparison operator</link>
to properly distinguish between a directory entry whose name is "falsy"
and having read all entries of the directory.
</simpara>
Comment on lines +93 to +101
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this need to be a warning or a note?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess so, maybe could even be a caution.

<programlisting role="php">
<![CDATA[
<?php
$dir = "/etc/php5/";
// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
echo "filename: $file : filetype: " . filetype($dir . $file) . "\n";
if ($handle = opendir('/path/to/files')) {
echo "Directory handle: $handle\n";
echo "Entries:\n";
/* Correctly handling directory entries that may be considered falsy */
while (false !== ($entry = readdir($handle))) {
if ($entry === '.' || $entry === '..') {
continue;
}
closedir($dh);
echo "$entry\n";
}
closedir($handle);
}
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
filename: . : filetype: dir
filename: .. : filetype: dir
filename: apache : filetype: dir
filename: cgi : filetype: dir
filename: cli : filetype: dir
]]>
Comment on lines 125 to 131
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The output doesn't match the code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't really have any output because it might be any filesystem, that's why we use the &example.outputs.similar; entity rather than &example.outputs;.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mean the file names. I meant the overal output structure is from the old example. You copied the other example without the copying the output also.

</screen>
</example>
</para>
</screen>
</example>
</refsect1>

<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>is_dir</function></member>
<member><function>readdir</function></member>
<member><function>dir</function></member>
</simplelist>
</para>
<simplelist>
<member><function>readdir</function></member>
<member><function>rewinddir</function></member>
<member><function>closedir</function></member>
<member><function>dir</function></member>
<member><function>is_dir</function></member>
<member><function>glob</function></member>
<member><function>scandir</function></member>
</simplelist>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Expand Down
Loading