On Mon, Nov 3, 2008 at 09:44, Lars Torben Wilson <[EMAIL PROTECTED]> wrote:
> 2008/11/2  <[EMAIL PROTECTED]>:
>>  ID:          46251
>>  Updated by:  [EMAIL PROTECTED]
>>  Reported By: php at pengi dot se
>> -Status:      Open
>> +Status:      Wont fix
>>  Bug Type:    Documentation problem
>>  PHP Version: Irrelevant
>>
>>
>> Previous Comments:
>> ------------------------------------------------------------------------
>>
>> [2008-10-08 10:55:36] php at pengi dot se
>>
>> This also applies to the next section of the example.
>>
>> $b = array();
>>
>> ------------------------------------------------------------------------
>>
>> [2008-10-07 23:45:51] php at pengi dot se
>>
>> Description:
>> ------------
>> First example under section Examples in documentation for Array type
>> says, that creating an array with array(initial value) is the same as
>> writing:
>>
>> $a[key] = value;
>> $a[key] = value;
>> $a[key] = value;
>>
>> but missing initialization of the variable.
>>
>> This may also be a security issue for people using this way of
>> initialization and also are using register_globals.
>>
>> What should be added to the example is:
>> $a = array();
>>
>> URL to related documentation page:
>> http://php.net/manual/en/language.types.array.php
>>
>> Reproduce code:
>> ---------------
>> // this
>> $a = array( 'color' => 'red',
>>            'taste' => 'sweet',
>>            'shape' => 'round',
>>            'name'  => 'apple',
>>                       4        // key will be 0
>>          );
>>
>> // is completely equivalent with
>> $a['color'] = 'red';
>> $a['taste'] = 'sweet';
>> $a['shape'] = 'round';
>> $a['name']  = 'apple';
>> $a[]        = 4;        // key will be 0
>
> I disagree with the decision to mark this "Won't Be Fixed"; the
> documentation is incorrect and the fix is simple.
>
>
> Index: en/language/types/array.xml
> ===================================================================
> RCS file: /repository/phpdoc/en/language/types/array.xml,v
> retrieving revision 1.4
> diff -u -u -r1.4 array.xml
> --- en/language/types/array.xml 21 Feb 2008 18:43:17 -0000      1.4
> +++ en/language/types/array.xml 3 Nov 2008 08:41:33 -0000
> @@ -597,26 +597,33 @@
>    <programlisting role="php">
>  <![CDATA[
>  <?php
> -// this
> +// This:
>  $a = array( 'color' => 'red',
>             'taste' => 'sweet',
>             'shape' => 'round',
>             'name'  => 'apple',
> -                       4        // key will be 0
> +            4        // key will be 0
>           );
>
> -// is completely equivalent with
> +$b = array('a', 'b', 'c');
> +
> +// . . .is completely equivalent with this:
> +$a = array();
>  $a['color'] = 'red';
>  $a['taste'] = 'sweet';
>  $a['shape'] = 'round';
>  $a['name']  = 'apple';
>  $a[]        = 4;        // key will be 0
>
> +$b = array();
>  $b[] = 'a';
>  $b[] = 'b';
>  $b[] = 'c';
> -// will result in the array array(0 => 'a' , 1 => 'b' , 2 => 'c'),
> -// or simply array('a', 'b', 'c')
> +
> +// After the above code is executed, $a will be the array
> +// array('color' => 'red', 'taste' => 'sweet', 'shape' => 'round',
> +// 'name' => 'apple', 0 => 4), and $b will be the array
> +// array(0 => 'a', 1 => 'b', 2 => 'c'), or simply array('a', 'b', 'c').
>  ?>
>  ]]>
>    </programlisting>


I think the "Wont fix" was due to the fact you can do $foo[] =
"value"; without initializing $foo = array() without getting any
notices or difference then initializing it beforehand.

Although we shouldn't be advocating such coding we still should
document it - adding (like the bug reporter correctly pointed out)
register_global issues note..

-Hannes

Reply via email to