php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #46251 Array type documentation, error in example
Submitted: 2008-10-07 23:45 UTC Modified: 2008-11-05 22:01 UTC
From: php at pengi dot se Assigned: torben (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: php at pengi dot se
New email:
PHP Version: OS:

 

 [2008-10-07 23:45 UTC] 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



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-10-08 10:55 UTC] php at pengi dot se
This also applies to the next section of the example.

$b = array();
 [2008-11-05 22:01 UTC] torben@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 03:00:02 2026 UTC