philip Tue Jan 21 02:17:32 2003 EDT Modified files: /phpdoc/en/language types.xml Log: Added <?php ?>, and missing CDATA's.
Index: phpdoc/en/language/types.xml diff -u phpdoc/en/language/types.xml:1.103 phpdoc/en/language/types.xml:1.104 --- phpdoc/en/language/types.xml:1.103 Sat Jan 18 12:31:07 2003 +++ phpdoc/en/language/types.xml Tue Jan 21 02:17:32 2003 @@ -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_string($bool)) { echo "String: $bool"; } +?> ]]> </programlisting> </informalexample> @@ -185,7 +187,9 @@ <informalexample> <programlisting role="php"> <![CDATA[ +<?php $foo = True; // assign the value TRUE to $foo +?> ]]> </programlisting> </informalexample> @@ -199,6 +203,7 @@ <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) { echo "<hr>\n"; } +?> ]]> </programlisting> </informalexample> @@ -283,6 +289,7 @@ <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) 2.3e5); // bool(true) echo gettype((bool) array(12)); // bool(true) echo gettype((bool) array()); // bool(false) +?> ]]> </programlisting> </informalexample> @@ -325,10 +333,12 @@ <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 @@ <informalexample> <programlisting> <![CDATA[ +<?php decimal : [1-9][0-9]* | 0 @@ -346,6 +357,7 @@ integer : [+-]?decimal | [+-]?hexadecimal | [+-]?octal +?> ]]> </programlisting> </informalexample> @@ -368,6 +380,7 @@ <informalexample> <programlisting role="php"> <![CDATA[ +<?php $large_number = 2147483647; var_dump($large_number); // output: int(2147483647) @@ -384,6 +397,7 @@ $large_number = 50000 * $million; var_dump($large_number); // output: float(50000000000) +?> ]]> </programlisting> </informalexample> @@ -410,9 +424,11 @@ <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 @@ <informalexample> <programlisting role="php"> <![CDATA[ +<?php echo (int) ( (0.1+0.7) * 10 ); // echoes 7! +?> ]]> </programlisting> </informalexample> @@ -511,7 +529,13 @@ 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 @@ <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 @@ // 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 @@ <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 @@ <informalexample> <programlisting role="php"> <![CDATA[ +<?php $fruits = array('strawberry' => 'red', 'banana' => 'yellow'); // note that this works differently outside string-quotes @@ -874,7 +903,7 @@ // 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 @@ <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 "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 @@ <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 = 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 @@ <informalexample> <programlisting role="php"> <![CDATA[ +<?php echo "\$foo==$foo; type is " . gettype ($foo) . "<br />\n"; +?> ]]> </programlisting> </informalexample> @@ -1169,7 +1204,9 @@ <informalexample> <programlisting role="php"> <![CDATA[ +<?php array("foo" => "bar", 12 => true); +?> ]]> </programlisting> </informalexample> @@ -1189,7 +1226,9 @@ <informalexample> <programlisting role="php"> <![CDATA[ +<?php array("somearray" => array(6 => 5, 13 => 9, "a" => 43)); +?> ]]> </programlisting> </informalexample> @@ -1205,11 +1244,13 @@ <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 @@ <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 @@ unset($arr[5]); // This removes the element from the array unset($arr); // This deletes the whole array +?> ]]> </programlisting> </informalexample> @@ -1288,6 +1331,7 @@ <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 @@ $b = array_values($a); // Now b is array(1 => 'one', 2 =>'three') +?> ]]> </programlisting> </informalexample> @@ -1323,9 +1368,11 @@ <informalexample> <programlisting role="php"> <![CDATA[ +<?php $foo[bar] = 'enemy'; echo $foo[bar]; // etc +?> ]]> </programlisting> </informalexample> @@ -1344,7 +1391,9 @@ <informalexample> <programlisting role="php"> <![CDATA[ +<?php echo $arr[foo(true)]; +?> ]]> </programlisting> </informalexample> @@ -1356,9 +1405,11 @@ <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 @@ <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 @@ <informalexample> <programlisting role="php"> <![CDATA[ +<?php // this $a = array( 'color' => 'red', 'taste' => 'sweet', @@ -1493,6 +1547,7 @@ $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 @@ <title>Using array()</title> <programlisting role="php"> <![CDATA[ +<?php // Array as (property-)map $map = array( 'version' => 4, 'OS' => 'Linux', @@ -1530,6 +1586,7 @@ // empty array $empty = array(); +?> ]]> <!-- TODO example of - overwriting keys @@ -1543,6 +1600,7 @@ <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 green? Do you like yellow? */ +?> ]]> </programlisting> </example> @@ -1573,6 +1632,7 @@ <title>Collection</title> <programlisting role="php"> <![CDATA[ +<?php foreach ($colors as $key => $color) { // won't work: //$color = strtoupper($color); @@ -1591,6 +1651,7 @@ [3] => YELLOW ) */ +?> ]]> </programlisting> </example> @@ -1601,6 +1662,7 @@ <title>One-based index</title> <programlisting role="php"> <![CDATA[ +<?php $firstquarter = array(1 => 'January', 'February', 'March'); print_r($firstquarter); @@ -1626,6 +1688,7 @@ $files[] = $file; } closedir($handle); +?> ]]> </programlisting> </example> @@ -1640,8 +1703,10 @@ <title>Sorting array</title> <programlisting role="php"> <![CDATA[ +<?php sort($files); print_r($files); +?> ]]> </programlisting> </example> @@ -1654,6 +1719,7 @@ <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 @@ // Create a new multi-dimensional array $juices["apple"]["green"] = "good"; +?> ]]> </programlisting> </example> @@ -1688,6 +1755,7 @@ <informalexample> <programlisting role="php"> <![CDATA[ +<?php $arr1 = array(2, 3); $arr2 = $arr1; $arr2[] = 4; // $arr2 is changed, @@ -1695,6 +1763,7 @@ $arr3 = &$arr1; $arr3[] = 4; // now $arr1 and $arr3 are the same +?> ]]> </programlisting> </informalexample> @@ -1749,8 +1818,12 @@ value. <informalexample> <programlisting role="php"> +<![CDATA[ +<?php $obj = (object) 'ciao'; echo $obj->scalar; // outputs 'ciao' +?> +]]> </programlisting> </informalexample> </para> @@ -1854,7 +1927,11 @@ the case-insensitive keyword &null;. <informalexample> <programlisting role="php"> +<![CDATA[ +<?php $var = NULL; +]]> +?> </programlisting> </informalexample> </para> @@ -1979,6 +2056,8 @@ 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 @@ - -'abc' = 'abc' --> +?> +]]> </programlisting> </informalexample> </para> @@ -2031,8 +2112,12 @@ <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 @@ 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 @@ 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 @@ the following are functionally equivalent: <informalexample> <programlisting role="php"> +<![CDATA[ +<?php $foo = (int) $bar; $foo = ( int ) $bar; +?> +]]> </programlisting> </informalexample> </para> @@ -2114,6 +2211,8 @@ 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 @@ if ($fst === $str) { echo "they are the same"; } +?> +]]> </programlisting> </informalexample> </para>
-- PHP Documentation Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php