[DOC-CVS] [doc-en] master: Add DateTime related serialize/unserialize methods (#4410)

[email protected] (Pierre Ambroise via GitHub)
Newsgroups php.doc.cvs
Message-ID <[email protected]>
Author: Pierre Ambroise (Fan2Shrek)
Committer: GitHub (web-flow)
Pusher: vrana
Date: 2025-05-04T09:22:39+02:00

Commit: https://github.com/php/doc-en/commit/053ae3f6f54cba66a12f85d2eebe32863c6f221e
Raw diff: https://github.com/php/doc-en/commit/053ae3f6f54cba66a12f85d2eebe32863c6f221e.diff

Add DateTime related serialize/unserialize methods (#4410)

Changed paths:
  A  reference/datetime/datetimeinterface/serialize.xml
  A  reference/datetime/datetimeinterface/unserialize.xml
  M  reference/datetime/versions.xml


Diff:

diff --git a/reference/datetime/datetimeinterface/serialize.xml b/reference/datetime/datetimeinterface/serialize.xml
new file mode 100644
index 000000000000..5615dca18157
--- /dev/null
+++ b/reference/datetime/datetimeinterface/serialize.xml
@@ -0,0 +1,90 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- $Revision$ -->
+<refentry xml:id="datetime.serialize" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
+ <refnamediv>
+  <refname>DateTime::__serialize</refname>
+  <refname>DateTimeImmutable::__serialize</refname>
+  <refname>DateTimeInterface::__serialize</refname>
+  <refpurpose>Serialize a DateTime</refpurpose>
+ </refnamediv>
+
+ <refsect1 role="description">
+  &reftitle.description;
+  <methodsynopsis role="DateTime">
+   <modifier>public</modifier> <type>array</type><methodname>DateTime::__serialize</methodname>
+   <void/>
+  </methodsynopsis>
+  <methodsynopsis role="DateTimeImmutable">
+   <modifier>public</modifier> <type>array</type><methodname>DateTimeImmutable::__serialize</methodname>
+   <void/>
+  </methodsynopsis>
+  <methodsynopsis role="DateTimeInterface">
+   <modifier>public</modifier> <type>array</type><methodname>DateTimeInterface::__serialize</methodname>
+   <void/>
+  </methodsynopsis>
+  <para>
+   The <link linkend="object.serialize">__serialize()</link> handler.
+  </para>
+ </refsect1>
+
+ <refsect1 role="parameters">
+  &reftitle.parameters;
+  &no.function.parameters;
+ </refsect1>
+
+ <refsect1 role="returnvalues">
+  &reftitle.returnvalues;
+  <para>
+   The serialized representation of the
+   <classname>DateTime</classname> object.
+  </para>
+ </refsect1>
+
+ <refsect1 role="examples">
+  &reftitle.examples;
+  <example>
+   <title><function>DateTime::serialize</function> example</title>
+   <programlisting role="php">
+<![CDATA[
+<?php
+$date = new DateTime('2025-03-27');
+var_dump(serialize($date));
+?>
+]]>
+   </programlisting>
+   &examples.outputs;
+   <screen>
+<![CDATA[
+string(114) "O:8:"DateTime":3:{s:4:"date";s:26:"2025-03-27 00:00:00.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:3:"UTC";}"
+]]>
+   </screen>
+  </example>
+ </refsect1>
+
+ <refsect1 role="seealso">
+  &reftitle.seealso;
+  <simplelist>
+   <member><methodname>DateTime::__unserialize</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
+-->
diff --git a/reference/datetime/datetimeinterface/unserialize.xml b/reference/datetime/datetimeinterface/unserialize.xml
new file mode 100644
index 000000000000..f60f36c4bb9e
--- /dev/null
+++ b/reference/datetime/datetimeinterface/unserialize.xml
@@ -0,0 +1,105 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- $Revision$ -->
+<refentry xml:id="datetime.unserialize" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
+ <refnamediv>
+  <refname>DateTime::__unserialize</refname>
+  <refname>DateTimeImmutable::__unserialize</refname>
+  <refname>DateTimeInterface::__unserialize</refname>
+  <refpurpose>Unserialize an Datetime</refpurpose>
+ </refnamediv>
+
+ <refsect1 role="description">
+  &reftitle.description;
+  <methodsynopsis role="DateTime">
+   <modifier>public</modifier> <type>void</type><methodname>DateTime::__unserialize</methodname>
+   <methodparam><type>array</type><parameter>data</parameter></methodparam>
+  </methodsynopsis>
+  <methodsynopsis role="DateTimeImmutable">
+   <modifier>public</modifier> <type>void</type><methodname>DateTimeImmutable::__unserialize</methodname>
+   <methodparam><type>array</type><parameter>data</parameter></methodparam>
+  </methodsynopsis>
+  <methodsynopsis role="DateTimeInterface">
+   <modifier>public</modifier> <type>void</type><methodname>DateTimeInterface::__unserialize</methodname>
+   <methodparam><type>array</type><parameter>data</parameter></methodparam>
+  </methodsynopsis>
+  <para>
+   The <link linkend="object.unserialize">__unserialize()</link> handler.
+  </para>
+ </refsect1>
+
+ <refsect1 role="parameters">
+  &reftitle.parameters;
+  <variablelist>
+   <varlistentry>
+    <term><parameter>data</parameter></term>
+    <listitem>
+     <para>
+      The serialized <classname>DateTime</classname>.
+     </para>
+    </listitem>
+   </varlistentry>
+  </variablelist>
+ </refsect1>
+
+ <refsect1 role="returnvalues">
+  &reftitle.returnvalues;
+  <para>
+   The <classname>DateTime</classname> object.
+  </para>
+ </refsect1>
+
+ <refsect1 role="examples">
+  &reftitle.examples;
+  <example>
+   <title><function>DateTime::unserialize</function> example</title>
+   <programlisting role="php">
+<![CDATA[
+<?php
+$serializedDate = 'O:8:"DateTime":3:{s:4:"date";s:26:"2025-03-27 00:00:00.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:3:"UTC";}';
+var_dump(unserialize($serializedDate));
+?>
+]]>
+   </programlisting>
+   &examples.outputs;
+   <screen>
+<![CDATA[
+object(DateTime)#1 (3) {
+  ["date"]=>
+  string(26) "2025-03-27 00:00:00.000000"
+  ["timezone_type"]=>
+  int(3)
+  ["timezone"]=>
+  string(3) "UTC"
+}
+]]>
+   </screen>
+  </example>
+ </refsect1>
+
+ <refsect1 role="seealso">
+  &reftitle.seealso;
+  <simplelist>
+   <member><methodname>DateTime::__serialize</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
+-->
diff --git a/reference/datetime/versions.xml b/reference/datetime/versions.xml
index 7791a424e736..f43198daf43a 100644
--- a/reference/datetime/versions.xml
+++ b/reference/datetime/versions.xml
@@ -8,6 +8,8 @@
  <function name="datetime" from="PHP 5 &gt;= 5.2.0, PHP 7, PHP 8"/>
  <function name="datetime::__construct" from="PHP 5 &gt;= 5.2.0, PHP 7, PHP 8"/>
  <function name="datetime::__set_state" from="PHP 5 &gt;= 5.3.0, PHP 7, PHP 8"/>
+ <function name="datetime::__serialize" from="PHP 8 &gt;= 8.2.0"/>
+ <function name="datetime::__unserialize" from="PHP 8 &gt;= 8.2.0"/>
  <function name="datetime::__wakeup" from="PHP 5 &gt;= 5.3.0, PHP 7, PHP 8"/>
  <function name="datetime::add" from="PHP 5 &gt;= 5.3.0, PHP 7, PHP 8"/>
  <function name="datetime::createfromformat" from="PHP 5 &gt;= 5.3.0, PHP 7, PHP 8"/>
@@ -28,6 +30,8 @@
  <function name="datetime::sub" from="PHP 5 &gt;= 5.3.0, PHP 7, PHP 8"/>
 
  <function name="datetimeinterface" from="PHP 5 &gt;= 5.5.0, PHP 7, PHP 8"/>
+ <function name="datetimeinterface::__serialize" from="PHP 8 &gt;= 8.2.0"/>
+ <function name="datetimeinterface::__unserialize" from="PHP 8 &gt;= 8.2.0"/>
  <function name="datetimeinterface::__wakeup" from="PHP 5 &gt;= 5.2.0, PHP 7, PHP 8"/>
  <function name="datetimeinterface::diff" from="PHP 5 &gt;= 5.3.0, PHP 7, PHP 8"/>
  <function name="datetimeinterface::format" from="PHP 5 &gt;= 5.2.0, PHP 7, PHP 8"/>
@@ -37,6 +41,8 @@
 
  <function name="datetimeimmutable" from="PHP 5 &gt;= 5.5.0, PHP 7, PHP 8"/>
  <function name="datetimeimmutable::__construct" from="PHP 5 &gt;= 5.5.0, PHP 7, PHP 8"/>
+ <function name="datetimeimmutable::__serialize" from="PHP 8 &gt;= 8.2.0"/>
+ <function name="datetimeimmutable::__unserialize" from="PHP 8 &gt;= 8.2.0"/>
  <function name="datetimeimmutable::__set_state" from="PHP 5 &gt;= 5.5.0, PHP 7, PHP 8"/>
  <function name="datetimeimmutable::__wakeup" from="PHP 5 &gt;= 5.5.0, PHP 7, PHP 8"/>
  <function name="datetimeimmutable::createfromformat" from="PHP 5 &gt;= 5.5.0, PHP 7, PHP 8"/>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.