[DOC-CVS] [doc-en] master: Enable WASM for book.var, and tweak examples

[email protected] (Derick Rethans)
Newsgroups php.doc.cvs
Message-ID <[email protected]>
Author: Derick Rethans (derickr)
Date: 2025-05-06T12:49:48+01:00

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

Enable WASM for book.var, and tweak examples

Changed paths:
  M  reference/var/book.xml
  M  reference/var/functions/get-debug-type.xml
  M  reference/var/functions/get-resource-type.xml
  M  reference/var/functions/intval.xml
  M  reference/var/functions/is-bool.xml
  M  reference/var/functions/is-countable.xml
  M  reference/var/functions/is-null.xml
  M  reference/var/functions/is-scalar.xml
  M  reference/var/functions/isset.xml
  M  reference/var/functions/print-r.xml
  M  reference/var/functions/serialize.xml
  M  reference/var/functions/settype.xml
  M  reference/var/functions/unserialize.xml
  M  reference/var/functions/unset.xml
  M  reference/var/functions/var-export.xml


Diff:

diff --git a/reference/var/book.xml b/reference/var/book.xml
index 724f34ed91a5..ea8d476b2373 100644
--- a/reference/var/book.xml
+++ b/reference/var/book.xml
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!-- $Revision$ -->
 
-<book xml:id="book.var" xmlns="http://docbook.org/ns/docbook">
+<book xml:id="book.var" xmlns="http://docbook.org/ns/docbook" annotations="interactive">
  <?phpdoc extension-membership="core" ?>
  <title>Variable handling</title>
 
diff --git a/reference/var/functions/get-debug-type.xml b/reference/var/functions/get-debug-type.xml
index 858d25603819..10adb6f64ae2 100644
--- a/reference/var/functions/get-debug-type.xml
+++ b/reference/var/functions/get-debug-type.xml
@@ -152,7 +152,7 @@ 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');
+$fp = fopen('/examples/book.xml', 'rb');
 echo get_debug_type($fp), PHP_EOL;
 
 fclose($fp);
diff --git a/reference/var/functions/get-resource-type.xml b/reference/var/functions/get-resource-type.xml
index 81d85a839b44..b94f525e1622 100644
--- a/reference/var/functions/get-resource-type.xml
+++ b/reference/var/functions/get-resource-type.xml
@@ -41,11 +41,11 @@
   <para>
    If the given <parameter>resource</parameter> is a resource, this function
    will return a string representing its type. If the type is not identified
-   by this function, the return value will be the string 
+   by this function, the return value will be the string
    <literal>Unknown</literal>.
   </para>
   <para>
-   This function will return &null; and generate an error if 
+   This function will return &null; and generate an error if
    <parameter>resource</parameter> is not a <type>resource</type>.
   </para>
  </refsect1>
@@ -60,10 +60,6 @@
 <?php
 $fp = fopen("foo", "w");
 echo get_resource_type($fp) . "\n";
-
-// As of PHP 8.0.0, the following does not work anymore. The curl_init function returns a CurlHandle object now.
-$c = curl_init();
-echo get_resource_type($c) . "\n";
 ?>
 ]]>
     </programlisting>
@@ -71,7 +67,6 @@ echo get_resource_type($c) . "\n";
     <screen role="php">
 <![CDATA[
 stream
-curl
 ]]>
     </screen>
    </example>
diff --git a/reference/var/functions/intval.xml b/reference/var/functions/intval.xml
index 9dcd39a1a1fa..77fe1d944910 100644
--- a/reference/var/functions/intval.xml
+++ b/reference/var/functions/intval.xml
@@ -131,27 +131,27 @@
     <programlisting role="php">
 <![CDATA[
 <?php
-echo intval(42);                      // 42
-echo intval(4.7);                     // 4
-echo intval('42');                    // 42
-echo intval('+42');                   // 42
-echo intval('-42');                   // -42
-echo intval(042);                     // 34
-echo intval('042');                   // 42
-echo intval(1e10);                    // 10000000000
-echo intval('1e10');                  // 10000000000
-echo intval(0x1A);                    // 26
-echo intval('0x1A');                  // 0
-echo intval('0x1A', 0);               // 26
-echo intval(42000000);                // 42000000
-echo intval(420000000000000000000);   // -4275113695319687168
-echo intval('420000000000000000000'); // 9223372036854775807
-echo intval(42, 8);                   // 42
-echo intval('42', 8);                 // 34
-echo intval(array());                 // 0
-echo intval(array('foo', 'bar'));     // 1
-echo intval(false);                   // 0
-echo intval(true);                    // 1
+echo intval(42), PHP_EOL;                      // 42
+echo intval(4.7), PHP_EOL;                     // 4
+echo intval('42'), PHP_EOL;                    // 42
+echo intval('+42'), PHP_EOL;                   // 42
+echo intval('-42'), PHP_EOL;                   // -42
+echo intval(042), PHP_EOL;                     // 34
+echo intval('042'), PHP_EOL;                   // 42
+echo intval(1e10), PHP_EOL;                    // 10000000000
+echo intval('1e10'), PHP_EOL;                  // 10000000000
+echo intval(0x1A), PHP_EOL;                    // 26
+echo intval('0x1A'), PHP_EOL;                  // 0
+echo intval('0x1A', 0), PHP_EOL;               // 26
+echo intval(42000000), PHP_EOL;                // 42000000
+echo intval(420000000000000000000), PHP_EOL;   // -4275113695319687168
+echo intval('420000000000000000000'), PHP_EOL; // 9223372036854775807
+echo intval(42, 8), PHP_EOL;                   // 42
+echo intval('42', 8), PHP_EOL;                 // 34
+echo intval(array()), PHP_EOL;                 // 0
+echo intval(array('foo', 'bar')), PHP_EOL;     // 1
+echo intval(false), PHP_EOL;                   // 0
+echo intval(true), PHP_EOL;                    // 1
 ?>
 ]]>
     </programlisting>
diff --git a/reference/var/functions/is-bool.xml b/reference/var/functions/is-bool.xml
index 6fe83459dac2..c679bd1eca59 100644
--- a/reference/var/functions/is-bool.xml
+++ b/reference/var/functions/is-bool.xml
@@ -52,12 +52,12 @@ $b = 0;
 
 // Since $a is a boolean, it will return true
 if (is_bool($a) === true) {
-    echo "Yes, this is a boolean";
+    echo "Yes, this is a boolean\n";
 }
 
 // Since $b is not a boolean, it will return false
 if (is_bool($b) === false) {
-    echo "No, this is not a boolean";
+    echo "No, this is not a boolean\n";
 }
 ?>
 ]]>
diff --git a/reference/var/functions/is-countable.xml b/reference/var/functions/is-countable.xml
index bd77e3591993..5c3b9c687fd0 100644
--- a/reference/var/functions/is-countable.xml
+++ b/reference/var/functions/is-countable.xml
@@ -78,7 +78,7 @@ var_dump(is_countable([1, 2, 3])); // bool(true)
 var_dump(is_countable(new ArrayIterator(['foo', 'bar', 'baz']))); // bool(true)
 var_dump(is_countable(new ArrayIterator())); // bool(true)
 var_dump(is_countable(new stdClass())); // bool(false)
-
+?>
 ]]>
     </programlisting>
    </example>   
diff --git a/reference/var/functions/is-null.xml b/reference/var/functions/is-null.xml
index 59a1001036ba..62ecad3773fe 100644
--- a/reference/var/functions/is-null.xml
+++ b/reference/var/functions/is-null.xml
@@ -56,16 +56,10 @@ var_dump(is_null($inexistent), is_null($foo));
 ?>
 ]]>
     </programlisting>
-    <screen>
-<![CDATA[
-Notice: Undefined variable: inexistent in ...
-bool(true)
-bool(true)
-]]>
-    </screen>
    </example>
   </para>
  </refsect1>
+
  <refsect1 role="seealso">
   &reftitle.seealso;
   <para>
diff --git a/reference/var/functions/is-scalar.xml b/reference/var/functions/is-scalar.xml
index 3185946bcbf6..2253e6b65a3b 100644
--- a/reference/var/functions/is-scalar.xml
+++ b/reference/var/functions/is-scalar.xml
@@ -73,11 +73,12 @@
 function show_var($var) 
 {
     if (is_scalar($var)) {
-        echo $var;
+        echo $var, PHP_EOL;
     } else {
         var_dump($var);
     }
 }
+
 $pi = 3.1416;
 $proteins = array("hemoglobin", "cytochrome c oxidase", "ferredoxin");
 
diff --git a/reference/var/functions/isset.xml b/reference/var/functions/isset.xml
index 290890212da2..46f967fd2867 100644
--- a/reference/var/functions/isset.xml
+++ b/reference/var/functions/isset.xml
@@ -80,7 +80,7 @@ $var = '';
 
 // This will evaluate to TRUE so the text will be printed.
 if (isset($var)) {
-    echo "This var is set so I will print.";
+    echo "This var is set so I will print.", PHP_EOL;
 }
 
 // In the next examples we'll use var_dump to output
@@ -107,7 +107,7 @@ var_dump(isset($foo));   // FALSE
   </para>
   <para>
    This also work for elements in arrays:
-   <informalexample>
+   <example>
     <programlisting role="php">
 <![CDATA[
 <?php
@@ -130,7 +130,7 @@ var_dump(isset($a['cake']['a']['b']));  // FALSE
 ?>
 ]]>
     </programlisting>
-   </informalexample>
+   </example>
   </para>
   <example>
    <title><function>isset</function> on String Offsets</title>
diff --git a/reference/var/functions/print-r.xml b/reference/var/functions/print-r.xml
index 2f616b95752e..a5630f2b2d29 100644
--- a/reference/var/functions/print-r.xml
+++ b/reference/var/functions/print-r.xml
@@ -101,7 +101,7 @@
 <pre>
 <?php
 $a = array ('a' => 'apple', 'b' => 'banana', 'c' => array ('x', 'y', 'z'));
-print_r ($a);
+print_r($a);
 ?>
 </pre>
 ]]>
@@ -134,6 +134,8 @@ Array
 <?php
 $b = array ('m' => 'monkey', 'foo' => 'bar', 'x' => array ('x', 'y', 'z'));
 $results = print_r($b, true); // $results now contains output from print_r
+
+print_r($results);
 ?>
 ]]>
     </programlisting>
diff --git a/reference/var/functions/serialize.xml b/reference/var/functions/serialize.xml
index d1ac09621fd9..246763a0fb0d 100644
--- a/reference/var/functions/serialize.xml
+++ b/reference/var/functions/serialize.xml
@@ -81,7 +81,7 @@
   <para>
    <example>
     <title><function>serialize</function> example</title>
-    <programlisting role="php">
+    <programlisting role="php" annotations="non-interactive">
 <![CDATA[
 <?php
 // $session_data contains a multi-dimensional array with session
diff --git a/reference/var/functions/settype.xml b/reference/var/functions/settype.xml
index e04a5acce40b..3700d30e64ab 100644
--- a/reference/var/functions/settype.xml
+++ b/reference/var/functions/settype.xml
@@ -100,6 +100,8 @@ $bar = true;   // boolean
 
 settype($foo, "integer"); // $foo is now 5   (integer)
 settype($bar, "string");  // $bar is now "1" (string)
+
+var_dump($foo, $bar);
 ?>
 ]]>
     </programlisting>
diff --git a/reference/var/functions/unserialize.xml b/reference/var/functions/unserialize.xml
index 22d69f84e48c..7dfee0a6968a 100644
--- a/reference/var/functions/unserialize.xml
+++ b/reference/var/functions/unserialize.xml
@@ -213,7 +213,7 @@
   <para>
    <example>
     <title><function>unserialize</function> example</title>
-    <programlisting role="php">
+    <programlisting role="php" annotations="non-interactive">
 <![CDATA[
 <?php
 // Here, we use unserialize() to load session data to the
@@ -253,7 +253,10 @@ function mycallback($classname)
 {
     // just include a file containing your class definition
     // you get $classname to figure out which class definition is required
+    var_dump($classname);
 }
+
+unserialize($serialized_object);
 ?>
 ]]>
     </programlisting>
diff --git a/reference/var/functions/unset.xml b/reference/var/functions/unset.xml
index 8396c1cf8588..922f9cd3c1f1 100644
--- a/reference/var/functions/unset.xml
+++ b/reference/var/functions/unset.xml
@@ -3,7 +3,7 @@
 <refentry xml:id="function.unset" xmlns="http://docbook.org/ns/docbook">
  <refnamediv>
   <refname>unset</refname>
-  <refpurpose>Unset a given variable</refpurpose>
+  <refpurpose><function>unset</function> a given variable</refpurpose>
  </refnamediv>
 
  <refsect1 role="description">
@@ -26,7 +26,8 @@
    a function, only the local variable is destroyed.  The variable
    in the calling environment will retain the same value as before
    <function>unset</function> was called.
-   <informalexample>
+   <example>
+    <title>Using <function>unset</function></title>
     <programlisting role="php">
 <![CDATA[
 <?php
@@ -42,23 +43,14 @@ echo $foo;
 ?>
 ]]>
     </programlisting>
-   </informalexample>
-  </para>
-  &example.outputs;
-  <para>
-   <informalexample>
-    <screen>
-<![CDATA[
-bar
-]]>
-    </screen>
-   </informalexample>
+   </example>
   </para>
   <para>
    To <function>unset</function> a global variable
    inside of a function, then use
    the <varname>$GLOBALS</varname> array to do so:
-   <informalexample>
+   <example>
+    <title><function>unset</function> a Global Variable</title>
     <programlisting role="php">
 <![CDATA[
 <?php
@@ -72,7 +64,7 @@ foo();
 ?>
 ]]>
     </programlisting>
-   </informalexample>
+   </example>
   </para>
   <para>
    If a variable that is PASSED BY REFERENCE is
@@ -80,7 +72,8 @@ foo();
    variable is destroyed.  The variable in the calling environment
    will retain the same value as before <function>unset</function>
    was called.
-   <informalexample>
+   <example>
+    <title><function>unset</function> with Reference</title>
     <programlisting role="php">
 <![CDATA[
 <?php
@@ -98,25 +91,15 @@ echo "$bar\n";
 ?>
 ]]>
     </programlisting>
-   </informalexample>
-  </para>
-   &example.outputs;
-  <para>
-   <informalexample>
-    <screen>
-<![CDATA[
-something
-something
-]]>
-    </screen>
-   </informalexample>
+   </example>
   </para>
   <para>
    If a static variable is <function>unset</function> inside of a
    function, <function>unset</function> destroys the variable only in the
    context of the rest of a function. Following calls will restore the
    previous value of a variable.
-   <informalexample>
+   <example>
+    <title><function>unset</function> with Static Variable</title>
     <programlisting role="php">
 <![CDATA[
 <?php
@@ -136,19 +119,7 @@ foo();
 ?>
 ]]>
     </programlisting>
-   </informalexample>
-  </para>
-   &example.outputs;
-  <para>
-   <informalexample>
-    <screen>
-<![CDATA[
-Before unset: 1, after unset: 23
-Before unset: 2, after unset: 23
-Before unset: 3, after unset: 23
-]]>
-    </screen>
-   </informalexample>
+   </example>
   </para>
  </refsect1>
 
@@ -188,7 +159,7 @@ Before unset: 3, after unset: 23
   <para>
    <example>
     <title><function>unset</function> example</title>
-    <programlisting role="php">
+    <programlisting role="php" annotations="non-interactive">
 <![CDATA[
 <?php
 // destroy a single variable
@@ -203,34 +174,6 @@ unset($foo1, $foo2, $foo3);
 ]]>
     </programlisting>
    </example>
-   <example>
-    <title>Using <literal>(unset)</literal> casting</title>
-    <para>
-     <link linkend="language.types.null.casting"><literal>(unset)</literal></link>
-     casting is often confused with the
-     <function>unset</function> function. <literal>(unset)</literal>
-     casting serves only as a <literal>NULL</literal>-type cast, for
-     completeness. It does not alter the variable it's casting.
-     The (unset) cast is deprecated as of PHP 7.2.0, removed as of 8.0.0.
-    </para>
-    <programlisting role="php">
-<![CDATA[
-<?php
-$name = 'Felipe';
-
-var_dump((unset) $name);
-var_dump($name);
-?>
-]]>
-    </programlisting>
-    &example.outputs;
-    <screen>
-<![CDATA[
-NULL
-string(6) "Felipe"
-]]>
-    </screen>
-   </example>
   </para>
  </refsect1>
 
diff --git a/reference/var/functions/var-export.xml b/reference/var/functions/var-export.xml
index c1d6877008af..66e2111d73b9 100644
--- a/reference/var/functions/var-export.xml
+++ b/reference/var/functions/var-export.xml
@@ -178,7 +178,7 @@ var_export($a);
     &example.outputs;
     <screen>
 <![CDATA[
-A::__set_state(array(
+\A::__set_state(array(
    'var' => 5,
 ))
 ]]>
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.