Added <?php ?> to PHP code.

Added ?> <?php to HTML code (until role="HTML" exists).
Changed $Count to $count in setcookie example.


git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@87068 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Philip Olson 2002-06-29 00:52:16 +00:00
parent bde354d7af
commit f3cc504884

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.50 $ -->
<!-- $Revision: 1.51 $ -->
<chapter id="language.variables">
<title>Variables</title>
@ -30,6 +30,7 @@
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
$var = "Bob";
$Var = "Joe";
echo "$var, $Var"; // outputs "Bob, Joe"
@ -37,6 +38,7 @@ echo "$var, $Var"; // outputs "Bob, Joe"
$4site = 'not yet'; // invalid; starts with a number
$_4site = 'not yet'; // valid; starts with an underscore
$täyte = 'mansikka'; // valid; 'ä' is ASCII 228.
?>
]]>
</programlisting>
</informalexample>
@ -285,8 +287,10 @@ $bar = &test(); // Invalid.
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
$a = 1;
include "b.inc";
?>
]]>
</programlisting>
</informalexample>
@ -301,6 +305,7 @@ include "b.inc";
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
$a = 1; /* global scope */
function Test()
@ -309,6 +314,7 @@ function Test()
}
Test();
?>
]]>
</programlisting>
</informalexample>
@ -329,6 +335,7 @@ Test();
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
$a = 1;
$b = 2;
@ -341,6 +348,7 @@ function Sum()
Sum();
echo $b;
?>
]]>
</programlisting>
</informalexample>
@ -362,6 +370,7 @@ echo $b;
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
$a = 1;
$b = 2;
@ -372,6 +381,7 @@ function Sum()
Sum();
echo $b;
?>
]]>
</programlisting>
</informalexample>
@ -393,12 +403,14 @@ echo $b;
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
function Test ()
{
$a = 0;
echo $a;
$a++;
}
?>
]]>
</programlisting>
</informalexample>
@ -416,12 +428,14 @@ function Test ()
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
function Test()
{
static $a = 0;
echo $a;
$a++;
}
?>
]]>
</programlisting>
</informalexample>
@ -444,6 +458,7 @@ function Test()
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
function Test()
{
static $count = 0;
@ -455,54 +470,7 @@ function Test()
}
$count--;
}
]]>
</programlisting>
</informalexample>
<simpara>
Static initializers are evaluated when a function is defined, not
when it is executed. Thus you cannot make reference to any other
variables or initialize a static variable with the result of a
function call. The following example suggests a way around this:
</simpara>
<informalexample>
<programlisting role="php">
<![CDATA[
function Test()
{
static $magic_quotes_initialized = false;
static $magic_quotes;
if (!$magic_quotes_initialized) {
$magic_quotes = get_magic_quotes_gpc();
$magic_quotes_initialized = true;
}
// function body
}
]]>
</programlisting>
</informalexample>
<simpara>
If the function you are calling has predictable return values, for
example, if it can never return <literal>null</literal>, this
can be further simplified (note the use of the identity operator
<literal>===</literal>):
</simpara>
<informalexample>
<programlisting role="php">
<![CDATA[
function Test()
{
static $magic_quotes = null;
if ($magic_quotes === null) {
$magic_quotes = get_magic_quotes_gpc();
}
// function body
}
?>
]]>
</programlisting>
</informalexample>
@ -519,6 +487,7 @@ function Test()
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
function test_global_ref() {
global $obj;
$obj = &new stdclass;
@ -533,6 +502,7 @@ test_global_ref();
var_dump($obj);
test_global_noref();
var_dump($obj);
?>
]]>
</programlisting>
</informalexample>
@ -555,6 +525,7 @@ object(stdClass)(0) {
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
function &get_instance_ref() {
static $obj;
@ -586,6 +557,7 @@ $still_obj1 = get_instance_ref();
echo "\n";
$obj2 = get_instance_noref();
$still_obj2 = get_instance_noref();
?>
]]>
</programlisting>
</informalexample>
@ -626,7 +598,9 @@ Static object: object(stdClass)(1) {
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
$a = "hello";
?>
]]>
</programlisting>
</informalexample>
@ -641,7 +615,9 @@ $a = "hello";
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
$$a = "world";
?>
]]>
</programlisting>
</informalexample>
@ -656,7 +632,9 @@ $$a = "world";
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
echo "$a ${$a}";
?>
]]>
</programlisting>
</informalexample>
@ -668,7 +646,9 @@ echo "$a ${$a}";
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
echo "$a $hello";
?>
]]>
</programlisting>
</informalexample>
@ -726,10 +706,12 @@ echo "$a $hello";
<title>Simple form variable</title>
<programlisting role="php">
<![CDATA[
?>
<form action="foo.php" method="post">
Name: <input type="text" name="username"><br>
<input type="submit">
</form>
<?php
]]>
</programlisting>
</example>
@ -767,6 +749,7 @@ echo "$a $hello";
<title>More complex form variables</title>
<programlisting role="php">
<![CDATA[
?>
<form action="array.php" method="post">
Name: <input type="text" name="personal[name]"><br>
Email: <input type="text" name="personal[email]"><br>
@ -778,6 +761,7 @@ echo "$a $hello";
</select>
<input type="submit">
</form>
<?php
]]>
</programlisting>
</example>
@ -798,7 +782,9 @@ echo "$a $hello";
<informalexample>
<programlisting role="php">
<![CDATA[
?>
<input type="image" src="image.gif" name="sub">
<?php
]]>
</programlisting>
</informalexample>
@ -840,7 +826,9 @@ echo "$a $hello";
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
setcookie("MyCookie[]", "Testing", time()+3600);
?>
]]>
</programlisting>
</informalexample>
@ -856,9 +844,11 @@ setcookie("MyCookie[]", "Testing", time()+3600);
<title>SetCookie Example</title>
<programlisting role="php">
<![CDATA[
$Count++;
setcookie("Count", $Count, time()+3600);
setcookie("Cart[$Count]", $item, time()+3600);
<?php
$count++;
setcookie("Count", $count, time()+3600);
setcookie("Cart[$count]", $item, time()+3600);
?>
]]>
</programlisting>
</example>
@ -875,7 +865,9 @@ setcookie("Cart[$Count]", $item, time()+3600);
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
echo $HOME; /* Shows the HOME environment variable, if set. */
?>
]]>
</programlisting>
</informalexample>
@ -902,7 +894,9 @@ echo $HOME; /* Shows the HOME environment variable, if set. */
variable name. For the reason, look at it:
<programlisting role="php">
<![CDATA[
<?php
$varname.ext; /* invalid variable name */
?>
]]>
</programlisting>
Now, what the parser sees is a variable named