Added <?php ?>, and missing CDATA's.

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@112919 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Philip Olson 2003-01-21 07:17:32 +00:00
parent 214208c4c1
commit c585222898

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.103 $ -->
<!-- $Revision: 1.104 $ -->
<chapter id="language.types">
<title>Types</title>
@ -127,6 +127,7 @@
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
$bool = TRUE; // a boolean
$str = "foo"; // a string
$int = 12; // an integer
@ -144,6 +145,7 @@ if (is_int($int)) {
if (is_string($bool)) {
echo "String: $bool";
}
?>
]]>
</programlisting>
</informalexample>
@ -185,7 +187,9 @@ if (is_string($bool)) {
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
$foo = True; // assign the value TRUE to $foo
?>
]]>
</programlisting>
</informalexample>
@ -199,6 +203,7 @@ $foo = True; // assign the value TRUE to $foo
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
// == is an operator which test
// equality and returns a boolean
if ($action == "show_version") {
@ -214,6 +219,7 @@ if ($show_separators == TRUE) {
if ($show_separators) {
echo "<hr>\n";
}
?>
]]>
</programlisting>
</informalexample>
@ -283,6 +289,7 @@ if ($show_separators) {
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
echo gettype((bool) ""); // bool(false)
echo gettype((bool) 1); // bool(true)
echo gettype((bool) -2); // bool(true)
@ -290,6 +297,7 @@ echo gettype((bool) "foo"); // bool(true)
echo gettype((bool) 2.3e5); // bool(true)
echo gettype((bool) array(12)); // bool(true)
echo gettype((bool) array()); // bool(false)
?>
]]>
</programlisting>
</informalexample>
@ -325,10 +333,12 @@ echo gettype((bool) array()); // bool(false)
<title>Integer literals</title>
<programlisting role="php">
<![CDATA[
<?php
$a = 1234; # decimal number
$a = -123; # a negative number
$a = 0123; # octal number (equivalent to 83 decimal)
$a = 0x1A; # hexadecimal number (equivalent to 26 decimal)
?>
]]>
</programlisting>
</example>
@ -336,6 +346,7 @@ $a = 0x1A; # hexadecimal number (equivalent to 26 decimal)
<informalexample>
<programlisting>
<![CDATA[
<?php
decimal : [1-9][0-9]*
| 0
@ -346,6 +357,7 @@ octal : 0[0-7]+
integer : [+-]?decimal
| [+-]?hexadecimal
| [+-]?octal
?>
]]>
</programlisting>
</informalexample>
@ -368,6 +380,7 @@ integer : [+-]?decimal
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
$large_number = 2147483647;
var_dump($large_number);
// output: int(2147483647)
@ -384,6 +397,7 @@ $million = 1000000;
$large_number = 50000 * $million;
var_dump($large_number);
// output: float(50000000000)
?>
]]>
</programlisting>
</informalexample>
@ -410,9 +424,11 @@ var_dump($large_number);
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
var_dump(25/7); // float(3.5714285714286)
var_dump((int) (25/7)); // int(3)
var_dump(round(25/7)); // float(4)
?>
]]>
</programlisting>
</informalexample>
@ -467,7 +483,9 @@ var_dump(round(25/7)); // float(4)
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
echo (int) ( (0.1+0.7) * 10 ); // echoes 7!
?>
]]>
</programlisting>
</informalexample>
@ -511,7 +529,13 @@ echo (int) ( (0.1+0.7) * 10 ); // echoes 7!
specified using any of the following syntaxes:
<informalexample>
<programlisting role="php">
$a = 1.234; $a = 1.2e3; $a = 7E-10;
<![CDATA[
<?php
$a = 1.234;
$b = 1.2e3;
$c = 7E-10;
?>
]]>
</programlisting>
</informalexample>
Formally:
@ -641,6 +665,7 @@ EXPONENT_DNUM ( ({LNUM} | {DNUM}) [eE][+-]? {LNUM})
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
echo 'this is a simple string';
echo 'You can also have embedded newlines in strings
this way';
@ -652,6 +677,7 @@ echo 'Are you sure you want to delete C:\*.*?';
// output: ... delete C:\*.*?
echo 'I am trying to include at this point: \n a newline';
// output: ... this point: \n a newline
?>
]]>
</programlisting>
</informalexample>
@ -841,10 +867,12 @@ EOT;
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
$beer = 'Heineken';
echo "$beer's taste is great"; // works, "'" is an invalid character for varnames
echo "He drank some $beers"; // won't work, 's' is a valid character for varnames
echo "He drank some ${beer}s"; // works
?>
]]>
</programlisting>
</informalexample>
@ -865,6 +893,7 @@ echo "He drank some ${beer}s"; // works
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
$fruits = array('strawberry' => 'red', 'banana' => 'yellow');
// note that this works differently outside string-quotes
@ -874,7 +903,7 @@ echo "This square is $square->width meters broad.";
// Won't work. For a solution, see the complex syntax.
echo "This square is $square->width00 centimeters broad.";
?>
]]>
<!-- XXX this won't work:
echo "This square is $square->{width}00 centimeters broad.";
@ -907,6 +936,7 @@ echo "This square is $square->{width}00 centimeters broad.";
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
$great = 'fantastic';
echo "This is { $great}"; // won't work, outputs: This is { fantastic}
echo "This is {$great}"; // works, outputs: This is fantastic
@ -920,6 +950,7 @@ echo "This is wrong: {$arr[foo][3]}";
echo "You should do it this way: {$arr['foo'][3]}";
echo "You can even write {$obj->values[3]->name}";
echo "This is the value of the var named $name: {${$name}}";
?>
]]>
<!-- maybe it's better to leave this out??
// this works, but i disencourage its use, since this is NOT
@ -1084,6 +1115,7 @@ $last = $str{strlen($str)-1};
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
$foo = 1 + "10.5"; // $foo is float (11.5)
$foo = 1 + "-1.3e3"; // $foo is float (-1299)
$foo = 1 + "bob-1.3e3"; // $foo is integer (1)
@ -1092,6 +1124,7 @@ $foo = 1 + "10 Small Pigs"; // $foo is integer (11)
$foo = 4 + "10.2 Little Piggies"; // $foo is float (14.2)
$foo = "10.0 pigs " + 1; // $foo is float (11)
$foo = "10.0 pigs " + 1.0; // $foo is float (11)
?>
]]>
</programlisting>
</informalexample>
@ -1106,7 +1139,9 @@ $foo = "10.0 pigs " + 1.0; // $foo is float (11)
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
echo "\$foo==$foo; type is " . gettype ($foo) . "<br />\n";
?>
]]>
</programlisting>
</informalexample>
@ -1169,7 +1204,9 @@ array( <optional> <replaceable>key</replaceable> =&gt; </optional> <replaceable
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
array("foo" => "bar", 12 => true);
?>
]]>
</programlisting>
</informalexample>
@ -1189,7 +1226,9 @@ array("foo" => "bar", 12 => true);
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
array("somearray" => array(6 => 5, 13 => 9, "a" => 43));
?>
]]>
</programlisting>
</informalexample>
@ -1205,11 +1244,13 @@ array("somearray" => array(6 => 5, 13 => 9, "a" => 43));
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
// This array is the same as ...
array(5 => 43, 32, 56, "b" => 12);
// ...this array
array(5 => 43, 6 => 32, 7 => 56, "b" => 12);
?>
]]>
</programlisting>
</informalexample>
@ -1254,6 +1295,7 @@ $arr[] = <replaceable>value</replaceable>;
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
$arr = array(5 => 1, 12 => 2);
$arr[] = 56; // This is the same as $arr[13] = 56;
@ -1265,6 +1307,7 @@ $arr["x"] = 42; // This adds a new element to
unset($arr[5]); // This removes the element from the array
unset($arr); // This deletes the whole array
?>
]]>
</programlisting>
</informalexample>
@ -1288,6 +1331,7 @@ unset($arr); // This deletes the whole array
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
$a = array(1 => 'one', 2 => 'two', 3 => 'three');
unset($a[2]);
/* will produce an array that would have been defined as
@ -1298,6 +1342,7 @@ unset($a[2]);
$b = array_values($a);
// Now b is array(1 => 'one', 2 =>'three')
?>
]]>
</programlisting>
</informalexample>
@ -1323,9 +1368,11 @@ $b = array_values($a);
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
$foo[bar] = 'enemy';
echo $foo[bar];
// etc
?>
]]>
</programlisting>
</informalexample>
@ -1344,7 +1391,9 @@ echo $foo[bar];
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
echo $arr[foo(true)];
?>
]]>
</programlisting>
</informalexample>
@ -1356,9 +1405,11 @@ echo $arr[foo(true)];
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
$error_descriptions[E_ERROR] = "A fatal error has occured";
$error_descriptions[E_WARNING] = "PHP issued a warning";
$error_descriptions[E_NOTICE] = "This is just an informal notice";
?>
]]>
</programlisting>
</informalexample>
@ -1368,9 +1419,11 @@ $error_descriptions[E_NOTICE] = "This is just an informal notice";
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
$error_descriptions[1] = "A fatal error has occured";
$error_descriptions[2] = "PHP issued a warning";
$error_descriptions[8] = "This is just an informal notice";
?>
]]>
</programlisting>
</informalexample>
@ -1473,6 +1526,7 @@ line <b>10</b><br />
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
// this
$a = array( 'color' => 'red',
'taste' => 'sweet',
@ -1493,6 +1547,7 @@ $b[] = 'b';
$b[] = 'c';
// will result in the array array(0 => 'a' , 1 => 'b' , 2 => 'c'),
// or simply array('a', 'b', 'c')
?>
]]>
</programlisting>
</informalexample>
@ -1502,6 +1557,7 @@ $b[] = 'c';
<title>Using array()</title>
<programlisting role="php">
<![CDATA[
<?php
// Array as (property-)map
$map = array( 'version' => 4,
'OS' => 'Linux',
@ -1530,6 +1586,7 @@ $switching = array( 10, // key = 0
// empty array
$empty = array();
?>
]]>
<!-- TODO example of
- overwriting keys
@ -1543,6 +1600,7 @@ $empty = array();
<title>Collection</title>
<programlisting role="php">
<![CDATA[
<?php
$colors = array('red', 'blue', 'green', 'yellow');
foreach ($colors as $color) {
@ -1555,6 +1613,7 @@ Do you like blue?
Do you like green?
Do you like yellow?
*/
?>
]]>
</programlisting>
</example>
@ -1573,6 +1632,7 @@ Do you like yellow?
<title>Collection</title>
<programlisting role="php">
<![CDATA[
<?php
foreach ($colors as $key => $color) {
// won't work:
//$color = strtoupper($color);
@ -1591,6 +1651,7 @@ Array
[3] => YELLOW
)
*/
?>
]]>
</programlisting>
</example>
@ -1601,6 +1662,7 @@ Array
<title>One-based index</title>
<programlisting role="php">
<![CDATA[
<?php
$firstquarter = array(1 => 'January', 'February', 'March');
print_r($firstquarter);
@ -1626,6 +1688,7 @@ while ($file = readdir($handle)) {
$files[] = $file;
}
closedir($handle);
?>
]]>
</programlisting>
</example>
@ -1640,8 +1703,10 @@ closedir($handle);
<title>Sorting array</title>
<programlisting role="php">
<![CDATA[
<?php
sort($files);
print_r($files);
?>
]]>
</programlisting>
</example>
@ -1654,6 +1719,7 @@ print_r($files);
<title>Recursive and multi-dimensional arrays</title>
<programlisting role="php">
<![CDATA[
<?php
$fruits = array ( "fruits" => array ( "a" => "orange",
"b" => "banana",
"c" => "apple"
@ -1678,6 +1744,7 @@ unset($fruits["holes"][0]); // remove "first"
// Create a new multi-dimensional array
$juices["apple"]["green"] = "good";
?>
]]>
</programlisting>
</example>
@ -1688,6 +1755,7 @@ $juices["apple"]["green"] = "good";
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
$arr1 = array(2, 3);
$arr2 = $arr1;
$arr2[] = 4; // $arr2 is changed,
@ -1695,6 +1763,7 @@ $arr2[] = 4; // $arr2 is changed,
$arr3 = &$arr1;
$arr3[] = 4; // now $arr1 and $arr3 are the same
?>
]]>
</programlisting>
</informalexample>
@ -1749,8 +1818,12 @@ $bar->do_foo();
value.
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
$obj = (object) 'ciao';
echo $obj-&gt;scalar; // outputs 'ciao'
?>
]]>
</programlisting>
</informalexample>
</para>
@ -1854,7 +1927,11 @@ echo $obj-&gt;scalar; // outputs 'ciao'
the case-insensitive keyword &null;.
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
$var = NULL;
]]>
?>
</programlisting>
</informalexample>
</para>
@ -1979,6 +2056,8 @@ call_user_function(array("foo", "bar")); // static class method call
how the operands are evaluated.
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
$foo = "0"; // $foo is string (ASCII 48)
<!-- bad example, no real operator (must be used with variable, modifies it too)
$foo++; // $foo is the string "1" (ASCII 49)
@ -2005,6 +2084,8 @@ examples:
- -'abc' = 'abc'
-->
?>
]]>
</programlisting>
</informalexample>
</para>
@ -2031,8 +2112,12 @@ examples:
<para>
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
$a = "1"; // $a is a string
$a[0] = "f"; // What about string offsets? What happens?
?>
]]>
</programlisting>
</informalexample>
</para>
@ -2052,8 +2137,12 @@ $a[0] = "f"; // What about string offsets? What happens?
above:
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
$a = "abc"; // $a is a string
$a{1} = "f"; // $a is now "afc"
?>
]]>
</programlisting>
</informalexample>
See the section titled <link linkend="language.types.string.substr">String
@ -2070,8 +2159,12 @@ $a{1} = "f"; // $a is now "afc"
is to be cast.
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
$foo = 10; // $foo is an integer
$bar = (boolean) $foo; // $bar is a boolean
?>
]]>
</programlisting>
</informalexample>
</para>
@ -2103,8 +2196,12 @@ $bar = (boolean) $foo; // $bar is a boolean
the following are functionally equivalent:
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
$foo = (int) $bar;
$foo = ( int ) $bar;
?>
]]>
</programlisting>
</informalexample>
</para>
@ -2114,6 +2211,8 @@ $foo = ( int ) $bar;
the variable in double quotes.
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
$foo = 10; // $foo is an integer
$str = "$foo"; // $str is a string
$fst = (string) $foo; // $fst is also a string
@ -2122,6 +2221,8 @@ $fst = (string) $foo; // $fst is also a string
if ($fst === $str) {
echo "they are the same";
}
?>
]]>
</programlisting>
</informalexample>
</para>