vrana           Tue Nov  1 09:37:01 2005 EDT

  Modified files:              
    /phpdoc/en/language variables.xml 
  Log:
  Uninitialized variables
  
http://cvs.php.net/diff.php/phpdoc/en/language/variables.xml?r1=1.88&r2=1.89&ty=u
Index: phpdoc/en/language/variables.xml
diff -u phpdoc/en/language/variables.xml:1.88 
phpdoc/en/language/variables.xml:1.89
--- phpdoc/en/language/variables.xml:1.88       Mon Oct 31 10:04:12 2005
+++ phpdoc/en/language/variables.xml    Tue Nov  1 09:37:00 2005
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.88 $ -->
+<!-- $Revision: 1.89 $ -->
  <chapter id="language.variables">
   <title>Variables</title>
   
@@ -109,6 +109,38 @@
      </programlisting>
     </informalexample>
    </para>
+   
+   <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.
+   </para>
+   <para>
+    <example>
+     <title>Default values of uninitialized variables</title>
+     <programlisting role="php">
+<![CDATA[
+<?php
+echo ($unset_bool ? "true" : "false"); // false
+$unset_int += 25; // 0 + 25 => 25
+echo $unset_string . "abc"; // "" . "abc" => "abc"
+$unset_array[3] = "def"; // array() + array(3 => "def") => array(3 => "def")
+?>
+]]>
+     </programlisting>
+    </example>
+   </para>
+   <para>
+    Relying on the default value of an uninitialized variable is problematic
+    in the case of including one file into another which uses the same
+    variable name. It is also a major <link
+    linkend="security.globals">security risk</link> with <link
+    linkend="ini.register-globals">register_globals</link> turned on. <link
+    linkend="e-notice">E_NOTICE</link> level error is issued in case of
+    working with uninitialized variables, however not in the case of appanding
+    elements to the uninitialized array. <function>isset</function> language
+    construct can be used to detect if a variable has been already initialized.
+   </para>
   </sect1>
 
   <sect1 id="language.variables.predefined">

Reply via email to