php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34137 assigning array element by reference causes binary mess
Submitted: 2005-08-15 17:28 UTC Modified: 2005-09-01 15:32 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: rashid at ds dot pg dot gda dot pl Assigned: dmitry
Status: Closed Package: Arrays related
PHP Version: 5CVS-2005-08-15 (snap) OS: windows xp
Private report: No CVE-ID:
 [2005-08-15 17:28 UTC] rashid at ds dot pg dot gda dot pl
Description:
------------
If you have an array which contains another array and you`ll assign reference to the inner array to the variable containing the outer array you`ll see all kinds of binary trash. With bigger arrays I`ve also seen Apache crashes.

I`ve used lates available 5.0.x snapshot:
Fri, 12 Aug 2005 19:09:17 +0200

Version: 5.0.5-dev
Branch: HEAD
Build: Release_TS

and lastes 5.1.x snapshot
Fri, 12 Aug 2005 23:13:30 +0000

Version: 5.1.0-dev
Branch: HEAD
Build: Release_TS

Reproduce code:
---------------
<?php
$arr1 = array('a1' => array('alfa' => 'beta'));

$arr1 =& $arr1['a1'];

echo '-'.$arr1['alfa'].'-';
?>

Expected result:
----------------
-beta-

Actual result:
--------------
--eta-

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-08-15 18:28 UTC] sniper@php.net
Where does it say that you are allowed to do that? 
(hint: Try var_dump() on it..)

 [2005-08-15 19:08 UTC] rashid at ds dot pg dot gda dot pl
how can something that crashes web server be a bogus?

var_dump shows that $arr1['alfa'] is null, which is also not true. The array is left in messed-up state after the assignment and lines after that the script suddenly crashes. If you access the same variable in two different ways and you see two different values, than something isn`t right.

There should be at least notice/warning/error on the line with assignment when assigning to the same variable or documentation note if it is not allowed.
 [2005-08-15 21:13 UTC] sniper@php.net
Dmitry, check this out please? (IMO, there's nothing wrong with getting "unexpected" result with this, but Antony insisted you might have something to say about this :)

 [2005-09-01 15:32 UTC] dmitry@php.net
Fixed in CVS HEAD, PHP_5_1, PHP_5_0 and PHP_4_4.
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Sun Apr 20 01:02:05 2014 UTC