hiphop-php /hphp/test/slow/array_for_each/variable-variable-foreach.php

Language PHP Lines 40
MD5 Hash ca446751cd5cf2b695066020b7e97e80 Estimated Cost $515 (why?)
Repository git://github.com/facebook/hiphop-php.git View Raw File View Project SPDX
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
$rows=array(1,2,3);


function fn1() {
    global $rows;
    global $row;
    $a="rows";
    $b="row";

    // TYPICAL FOREACH
    foreach($rows as $row) {
        fn2();
    }

    // USING VARIABLE VARIABLE
    foreach($$a as $$b) {
        fn2();
    }

    // THE MALFORMED ARRAY
    foreach($rows as $row) {
        fn2();
    }
}

function fn2() {
    global $row;
    echo "row=${row}\n";
}

// ORIGINAL ARRAY
print_r($rows);

// SOME ITERATIONS
fn1();

// THE MALFORMED ARRAY
print_r($rows);
Back to Top