php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26030 array passed by reference is modified but should'nt be
Submitted: 2003-10-29 12:02 UTC Modified: 2003-10-29 19:45 UTC
From: kevin at hatry dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: Irrelevant OS: Irrelevant
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: kevin at hatry dot com
New email:
PHP Version: OS:

 

 [2003-10-29 12:02 UTC] kevin at hatry dot com
Description:
------------
When passing a non-existing portion of an array by reference this portion gets created even if the function does not touch the array => it is modified in the calling line.

It works with string indexes as well.

Reproduce code:
---------------
error_reporting(E_ALL);

$tab2 = array( );

function do_nothing ( &$var ) { 
// code here doesnt matter
}

do_nothing($tab2[10]);
var_dump($tab2);



Expected result:
----------------
array(0) {
}


Actual result:
--------------
array(1) {
  [10]=>
  NULL
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-10-29 14:12 UTC] moriyoshi@php.net
Related to bug #25996

 [2003-10-29 19:45 UTC] sniper@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. Because of this, we hope you add your comments
to the existing bug instead.

Thank you for your interest in PHP.


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 06 11:02:27 2025 UTC