php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70550 Reference to undeclared array element, creates element
Submitted: 2015-09-22 07:15 UTC Modified: 2015-09-22 08:02 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: michal at econnect4u dot pl Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.6.13 OS: Widnows
Private report: No CVE-ID: None
 [2015-09-22 07:15 UTC] michal at econnect4u dot pl
Description:
------------
Reference to undeclared array element, creates element, instead return null pointer.

Test script:
---------------
$array = array('a');
print_r($array);
$a= &$array[4];
print_r($array);

$array2 = array('b');
print_r($array2);
$a= $array2[4];
print_r($array2);

Expected result:
----------------
Array
(
    [0] => a
)
Array
(
    [0] => a
)

Actual result:
--------------
Array
(
    [0] => a
)
Array
(
    [0] => a
    [4] => 
)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-09-22 08:02 UTC] requinix@php.net
-Status: Open +Status: Not a bug -Package: PHP Language Specification +Package: Scripting Engine problem
 [2015-09-22 08:02 UTC] requinix@php.net
null is not a pointer. PHP does not have pointers.

For a reference to exist, the thing it is a reference of must also exist. Trying to make a reference to something that does not exist will therefore cause it to be created for you.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 01:00:01 2026 UTC