php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #11541 weird behaviour with references and foreach
Submitted: 2001-06-18 14:20 UTC Modified: 2001-06-18 22:18 UTC
From: jens dot dreger at physik dot fu-berlin dot de Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 4.0.4pl1 OS: Linux Redhat 6.2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jens dot dreger at physik dot fu-berlin dot de
New email:
PHP Version: OS:

 

 [2001-06-18 14:20 UTC] jens dot dreger at physik dot fu-berlin dot de
<?php
echo "<small><pre>";

/* for some reason the following code magically kills
   an array value, or better, overwrites it with another one.
   might be related to bug #6417 */

$arr = array('a','b');
$ref =& $arr[0];

print_r($arr);
/* gives: Array ( [0] => a [1] => b ) */

foreach($arr as $ref);
print_r($arr);

/* gives: Array ( [0] => b [1] => b ) */
?>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-06-18 14:29 UTC] jens dot dreger at physik dot fu-berlin dot de
well, maybe this behaviour is not so weird as I tought...
the problem I had, was that the line taking the reference
and the foreach-statement were far apart, and I'd really
like to have localized variables in the foreach, like
foreach($arr as (my $val))...
 [2001-06-18 22:18 UTC] andre@php.net
no bug, closing

ps. this is PHP there won't be local variables like the ones you proposed in the near future I guess
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 00:01:41 2024 UTC