From 07e081dd58045b5195757945e853bb69fa770ab1 Mon Sep 17 00:00:00 2001 From: Ross Masters Date: Wed, 8 Oct 2008 19:50:07 +0000 Subject: [PATCH] Reworded how typing works and rewrote example to help show it. Fixed bug #45207 (Incorrect or missing documentation for languages.variables) git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@267083 c90b9560-bf6c-de11-be94-00142212c4b1 --- language/variables.xml | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/language/variables.xml b/language/variables.xml index 686765b017..335ff124d4 100644 --- a/language/variables.xml +++ b/language/variables.xml @@ -1,5 +1,5 @@ - + Variables @@ -121,8 +121,9 @@ $bar = &test(); // Invalid. 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 echo) are + set as an empty string and arrays become to an empty array. @@ -130,10 +131,32 @@ $bar = &test(); // Invalid. 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); ?> ]]>