1
0
mirror of https://github.com/php/doc-en.git synced 2026-03-23 23:32:18 +01:00

Enable WASM for book.var, and tweak examples

This commit is contained in:
Derick Rethans
2025-05-06 12:49:48 +01:00
parent 45042fef65
commit d816a0fad6
15 changed files with 59 additions and 119 deletions

View File

@@ -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>

View File

@@ -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);

View File

@@ -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>

View File

@@ -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>

View File

@@ -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";
}
?>
]]>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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");

View File

@@ -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>

View File

@@ -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>

View File

@@ -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

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -178,7 +178,7 @@ var_export($a);
&example.outputs;
<screen>
<![CDATA[
A::__set_state(array(
\A::__set_state(array(
'var' => 5,
))
]]>