php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43168 Odd array behavior
Submitted: 2007-11-01 11:14 UTC Modified: 2007-11-12 10:00 UTC
From: felipensp at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3CVS-2007-11-01 (snap) OS: Linux
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: felipensp at gmail dot com
New email:
PHP Version: OS:

 

 [2007-11-01 11:14 UTC] felipensp at gmail dot com
Description:
------------
See the result of code.

Reproduce code:
---------------
<?php

$a = range(1,10);
foreach ($a as &$b) {
  // normal
  # $a[0] = $a;   
  
  // keys: 1,2,3 - seg. fault
  # $a[1] = $a;  
  
  // odd result
  $a[4] = $a;    
   
  //5... - seg. fault                 
} 

var_dump($a);


Actual result:
--------------
Keys:
- Normal: 0
- Seg. fault: 1,2,3,5... (this isn't a bug, right?)
- Odd: 4

array(10) {
  [0]=>
  int(139421480)
  [1]=>
  int(2)
  [2]=>
  int(139421820)
  [3]=>
  int(139421252)
  [4]=>
  &array(10) {
    [0]=>
    int(139421480)
    [1]=>
    int(2)
    [2]=>
    int(139421820)
    [3]=>
    int(139421252)
    [4]=>
    &array(10) {
      [0]=>
      int(139421480)
      [1]=>
      int(2)
      [2]=>
      int(139421820)
      [3]=>
      int(139421252)
      [4]=>
      *RECURSION*
      [5]=>
      &int(139421480)
      [6]=>
      int(139421752)
      [7]=>
      int(139421616)
      [8]=>
      NULL
      [9]=>
      &int(139421480)
    }
    [5]=>
    &int(139421480)
    [6]=>
    int(139421752)
    [7]=>
    int(139421616)
    [8]=>
    NULL
    [9]=>
    &int(139421480)
  }
  [5]=>
  &int(139421480)
  [6]=>
  int(139421752)
  [7]=>
  int(139421616)
  [8]=>
  NULL
  [9]=>
  &int(139421480)
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-11-01 23:20 UTC] felipensp at gmail dot com
In PHP 5.2.3 key 4 cause too seg. fault.
 [2007-11-12 10:00 UTC] tony2001@php.net
You're looping over a variable that references itself, no wonder you get strange results and/or segfaults.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Sep 17 17:00:01 2025 UTC