-
Notifications
You must be signed in to change notification settings - Fork 831
Rework documentation for dir functions #4989
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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> | ||
|
|
@@ -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"> | ||
|
|
@@ -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> | ||
| <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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The output doesn't match the code.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.