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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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: Sat Dec 21 18:01:29 2024 UTC