cvs: phpdoc /en/language variables.xml

From: Date: Wed, 08 Oct 2008 19:50:08 +0000
Subject: cvs: phpdoc /en/language variables.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-2216@lists.php.net to get a copy of this message
ross Wed Oct 8 19:50:08 2008 UTC Modified files: /phpdoc/en/language variables.xml Log: Reworded how typing works and rewrote example to help show it. Fixed bug #45207 (Incorrect or missing documentation for languages.variables) http://cvs.php.net/viewvc.cgi/phpdoc/en/language/variables.xml?r1=1.103&r2=1.104&diff_format=u Index: phpdoc/en/language/variables.xml diff -u phpdoc/en/language/variables.xml:1.103 phpdoc/en/language/variables.xml:1.104 --- phpdoc/en/language/variables.xml:1.103 Wed Sep 17 10:25:43 2008 +++ phpdoc/en/language/variables.xml Wed Oct 8 19:50:07 2008 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.103 $ --> +<!-- $Revision: 1.104 $ --> <chapter xml:id="language.variables" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"> <title>Variables</title> @@ -121,8 +121,9 @@ <para> It is not necessary to initialize variables in PHP however it is a very - good practice. Uninitialized variables have a default value of their type - - &false;, zero, empty string or an empty array. + good practice. Uninitialized variables have a default value of their type depending on the context in which they are used + - booleans default to &false;, integers and floats default to zero, strings (e.g. used in <function>echo</function>) are + set as an empty string and arrays become to an empty array. </para> <para> <example> @@ -130,10 +131,32 @@ <programlisting role="php"> <![CDATA[ <?php -echo ($unset_bool ? "true" : "false"); // false +// Unset AND unreferenced (no use context) variable; outputs NULL +var_dump($unset_var); + +// Boolean usage; outputs 'false' (See ternary operators for more on this syntax) +echo($unset_bool ? "true\n" : "false\n"); + +// String usage; outputs 'string(3) "abc"' +$unset_str .= 'abc'; +var_dump($unset_str); + +// Integer usage; outputs 'int(25)' $unset_int += 25; // 0 + 25 => 25 -echo $unset_string . "abc"; // "" . "abc" => "abc" -$unset_array[3] = "def"; // array() + array(3 => "def") => array(3 => "def") +var_dump($unset_int); + +// Float/double usage; outputs 'float(1.25)' +$unset_float += 1.25; +var_dump($unset_float); + +// Array usage; outputs array(1) { [3]=> string(3) "def" } +$unset_arr[3] = "def"; // array() + array(3 => "def") => array(3 => "def") +var_dump($unset_arr); + +// Object usage; creates new stdClass object (see http://www.php.net/manual/en/reserved.classes.php) +// Outputs: object(stdClass)#1 (1) { ["foo"]=> string(3) "bar" } +$unset_obj->foo = 'bar'; +var_dump($unset_obj); ?> ]]> </programlisting>

« previous php.doc.cvs (#2216) next »