[doc-en] master: Document ZipArchive::openString() and ZipArchive::closeString() (#6135)
| From: | Shane Rounce via GitHub | Date: | Tue, 24 Nov 2026 14:49:17 +0000 |
| Subject: | [doc-en] master: Document ZipArchive::openString() and ZipArchive::closeString() (#6135) | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-24007@lists.php.net to get a copy of this message | ||
Author: Shane Rounce (AceMedia)
Committer: GitHub (web-flow)
Pusher: lacatoire
Date: 2026-11-24T15:49:13+01:00
Commit: https://github.com/php/doc-en/commit/1869c86aecc6fba27f64bcb3992f0e51d7e05bae
Raw diff: https://github.com/php/doc-en/commit/1869c86aecc6fba27f64bcb3992f0e51d7e05bae.diff
Document ZipArchive::openString() and ZipArchive::closeString() (#6135)
* Document ZipArchive::openString() and ZipArchive::closeString()
Both methods were added in PHP 8.6.0 and are listed in the 8.6 migration
guide, but have no manual pages. Add them, with the version entries.
Behaviour checked against PHP-8.6 with libzip 1.11.4.
* Address review of the ZipArchive::openString() docs
* Use exceptionname for Error in ZipArchive::closeString()
* Unwrap the seealso simplelist in ZipArchive::closeString()
---------
Co-authored-by: lacatoire <la.catoire@gmail.com>
Changed paths:
A reference/zip/ziparchive/closestring.xml
A reference/zip/ziparchive/openstring.xml
M reference/zip/versions.xml
Diff:
diff --git a/reference/zip/versions.xml b/reference/zip/versions.xml
index 63a0688c893d..d958230c8389 100644
--- a/reference/zip/versions.xml
+++ b/reference/zip/versions.xml
@@ -11,6 +11,7 @@
<function name="ZipArchive::addPattern" from="PHP 5 >= 5.3.0, PHP 7, PHP
8, PECL zip >= 1.9.0"/>
<function name="ZipArchive::clearError" from="PHP 8 >= 8.2.0, PECL zip
>= 1.20.0"/>
<function name="ZipArchive::close" from="PHP 5 >= 5.2.0, PHP 7, PHP 8,
PECL zip >= 1.1.0"/>
+ <function name="ZipArchive::closeString" from="PHP >= 8.6.0"/>
<function name="ZipArchive::count" from="PHP 7 >= 7.2.0, PHP 8, PECL zip
>= 1.15.0"/>
<function name="ZipArchive::deleteIndex" from="PHP 5 >= 5.2.0, PHP 7, PHP
8, PECL zip >= 1.5.0"/>
<function name="ZipArchive::deleteName" from="PHP 5 >= 5.2.0, PHP 7, PHP
8, PECL zip >= 1.5.0"/>
@@ -32,6 +33,7 @@
<function name="ZipArchive::isEncryptionMethodSupported" from="PHP >=
8.0.0, PECL zip >= 1.19.0"/>
<function name="ZipArchive::locateName" from="PHP 5 >= 5.2.0, PHP 7, PHP
8, PECL zip >= 1.5.0"/>
<function name="ZipArchive::open" from="PHP 5 >= 5.2.0, PHP 7, PHP 8,
PECL zip >= 1.1.0"/>
+ <function name="ZipArchive::openString" from="PHP >= 8.6.0"/>
<function name="ZipArchive::renameIndex" from="PHP 5 >= 5.2.0, PHP 7, PHP
8, PECL zip >= 1.5.0"/>
<function name="ZipArchive::renameName" from="PHP 5 >= 5.2.0, PHP 7, PHP
8, PECL zip >= 1.5.0"/>
<function name="ZipArchive::replaceFile" from="PHP >= 8.0.0, PECL zip
>= 1.18.0"/>
diff --git a/reference/zip/ziparchive/closestring.xml b/reference/zip/ziparchive/closestring.xml
new file mode 100644
index 000000000000..6bcfa32a2728
--- /dev/null
+++ b/reference/zip/ziparchive/closestring.xml
@@ -0,0 +1,105 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- $Revision$ -->
+<refentry xml:id="ziparchive.closestring" xmlns="http://docbook.org/ns/docbook">
+ <refnamediv>
+ <refname>ZipArchive::closeString</refname>
+ <refpurpose>Close the active archive and return it as a string</refpurpose>
+ </refnamediv>
+ <refsect1 role="description">
+ &reftitle.description;
+ <methodsynopsis role="ZipArchive">
+ <modifier>public</modifier> <type
class="union"><type>string</type><type>false</type></type><methodname>ZipArchive::closeString</methodname>
+ <void/>
+ </methodsynopsis>
+ <simpara>
+ Closes an archive that was opened with
+ <methodname>ZipArchive::openString</methodname>, saves any changes, and
+ returns the resulting archive as a string.
+ </simpara>
+ <note>
+ <simpara>
+ As with <methodname>ZipArchive::close</methodname>, a new archive that
+ contains no entries is not written. In that case an empty string is
+ returned, which is not a valid ZIP archive.
+ </simpara>
+ </note>
+ </refsect1>
+
+ <refsect1 role="parameters">
+ &reftitle.parameters;
+ &no.function.parameters;
+ </refsect1>
+
+ <refsect1 role="returnvalues">
+ &reftitle.returnvalues;
+ <simpara>
+ Returns the contents of the archive as a string, or &false; on failure.
+ When it fails, a warning is raised and the reason is available from
+ <methodname>ZipArchive::getStatusString</methodname>.
+ </simpara>
+ </refsect1>
+
+ <refsect1 role="errors">
+ &reftitle.errors;
+ <simpara>
+ Throws an <exceptionname>Error</exceptionname> if the archive was not opened with
+ <methodname>ZipArchive::openString</methodname>, and a
+ <exceptionname>ValueError</exceptionname> if the archive is not open, for
+ example because it has already been closed.
+ </simpara>
+ </refsect1>
+
+ <refsect1 role="examples">
+ &reftitle.examples;
+ <example xml:id="ziparchive.closestring.example.basic">
+ <title>Building an archive in memory</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+$zip = new ZipArchive;
+$zip->openString();
+$zip->addFromString('hello.txt', "Hello\n");
+$bytes = $zip->closeString();
+
+var_dump(is_string($bytes), str_starts_with($bytes, "PK"));
+?>
+]]>
+ </programlisting>
+ &example.outputs;
+ <screen>
+<![CDATA[
+bool(true)
+bool(true)
+]]>
+ </screen>
+ </example>
+ </refsect1>
+
+ <refsect1 role="seealso">
+ &reftitle.seealso;
+ <simplelist>
+ <member><methodname>ZipArchive::openString</methodname></member>
+ <member><methodname>ZipArchive::close</methodname></member>
+ </simplelist>
+ </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
+-->
\ No newline at end of file
diff --git a/reference/zip/ziparchive/openstring.xml b/reference/zip/ziparchive/openstring.xml
new file mode 100644
index 000000000000..b9f34df38195
--- /dev/null
+++ b/reference/zip/ziparchive/openstring.xml
@@ -0,0 +1,116 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- $Revision$ -->
+<refentry xml:id="ziparchive.openstring" xmlns="http://docbook.org/ns/docbook">
+ <refnamediv>
+ <refname>ZipArchive::openString</refname>
+ <refpurpose>Open a ZIP archive held in a string</refpurpose>
+ </refnamediv>
+ <refsect1 role="description">
+ &reftitle.description;
+ <methodsynopsis role="ZipArchive">
+ <modifier>public</modifier> <type
class="union"><type>bool</type><type>int</type></type><methodname>ZipArchive::openString</methodname>
+ <methodparam
choice="opt"><type>string</type><parameter>data</parameter><initializer>""</initializer></methodparam>
+ <methodparam
choice="opt"><type>int</type><parameter>flags</parameter><initializer>0</initializer></methodparam>
+ </methodsynopsis>
+ <simpara>
+ Opens a ZIP archive whose contents are held in a string, instead of in a
+ file. Called without arguments, it starts a new, empty archive in memory.
+ Use <methodname>ZipArchive::closeString</methodname> to get the resulting
+ archive back as a string.
+ </simpara>
+ </refsect1>
+
+ <refsect1 role="parameters">
+ &reftitle.parameters;
+ <variablelist>
+ <varlistentry>
+ <term><parameter>data</parameter></term>
+ <listitem>
+ <simpara>
+ The contents of an existing ZIP archive. The default, an empty string,
+ creates a new archive.
+ </simpara>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><parameter>flags</parameter></term>
+ <listitem>
+ <simpara>
+ A bitmask of flags, as for <methodname>ZipArchive::open</methodname>,
+ for example <constant>ZipArchive::CHECKCONS</constant>.
+ <constant>ZipArchive::EXCL</constant> always fails with
+ <constant>ZipArchive::ER_EXISTS</constant>, as there is no file, and
+ <constant>ZipArchive::CREATE</constant> has no effect.
+ </simpara>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </refsect1>
+
+ <refsect1 role="returnvalues">
+ &reftitle.returnvalues;
+ <simpara>
+ Returns &true; on success or the error code on failure, for example
+ <constant>ZipArchive::ER_NOZIP</constant> if <parameter>data</parameter>
+ is not a ZIP archive.
+ </simpara>
+ </refsect1>
+
+ <refsect1 role="examples">
+ &reftitle.examples;
+ <example xml:id="ziparchive.openstring.example.basic">
+ <title>Creating an archive in memory</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+$zip = new ZipArchive;
+$zip->openString();
+$zip->addFromString('hello.txt', "Hello\n");
+$bytes = $zip->closeString();
+
+// $bytes can be sent to a client or stored, and read back later.
+$zip = new ZipArchive;
+var_dump($zip->openString($bytes));
+var_dump($zip->getFromName('hello.txt'));
+?>
+]]>
+ </programlisting>
+ &example.outputs;
+ <screen>
+<![CDATA[
+bool(true)
+string(6) "Hello
+"
+]]>
+ </screen>
+ </example>
+ </refsect1>
+
+ <refsect1 role="seealso">
+ &reftitle.seealso;
+ <simplelist>
+ <member><methodname>ZipArchive::closeString</methodname></member>
+ <member><methodname>ZipArchive::open</methodname></member>
+ </simplelist>
+ </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
+-->
\ No newline at end of file