colder Sat Feb 24 11:19:24 2007 UTC
Modified files: /phpdoc/en/language references.xml Log: Fix #40610 (Undefined variables get defined when used with references) http://cvs.php.net/viewvc.cgi/phpdoc/en/language/references.xml?r1=1.46&r2=1.47&diff_format=u Index: phpdoc/en/language/references.xml diff -u phpdoc/en/language/references.xml:1.46 phpdoc/en/language/references.xml:1.47 --- phpdoc/en/language/references.xml:1.46 Fri Nov 18 16:20:48 2005 +++ phpdoc/en/language/references.xml Sat Feb 24 11:19:24 2007 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.46 $ --> +<!-- $Revision: 1.47 $ --> <chapter id="language.references"> <title>References Explained</title> @@ -49,6 +49,32 @@ This is valid also for arrays passed by value to functions. </para> </note> + <note> + <para> + If you assign, pass or return an undefined variable by reference, + it will get created. + <example> + <title>Using references with undefined variables</title> + <programlisting role="php"> +<![CDATA[ +<?php +function foo(&$var) { } + +foo($a); // $a is "created" and assigned to null + +$b = array(); +foo($b['b']); +var_dump(array_key_exists('b', $b)); // bool(true) + +$c = new StdClass; +foo($c->d); +var_dump(property_exists($c, 'd')); // bool(true) +?> +]]> + </programlisting> + </example> + </para> + </note> <para> The same syntax can be used with functions, that return references, and with <literal>new</literal> operator (in PHP 4.0.4 and later):