Skip to content

[Bug] Incorrect behavior of whenTrue/whenFalse method of ControlStructure of PHP foreach statement #5687

@xywang18

Description

@xywang18
<?php
$arr = $_GET['arr'];
foreach ($arr as $key => $value) {
  echo $value;
}
echo 111;

here is the dot foramt of the CFG of this method

digraph G {
  0 [label = "$iter_tmp0"];
  1 [label = "$_GET"];
  2 [label = "!is_null($value)"];
  3 [label = "$arr"];
  4 [label = "$key = $iter_tmp0->key()"];
  5 [label = "$value"];
  6 [label = "$value = $iter_tmp0->current()"];
  7 [label = "$value"];
  8 [label = "$iter_tmp0 = $arr"];
  9 [label = "$iter_tmp0->current()"];
  10 [label = "$iter_tmp0"];
  11 [label = "111"];
  12 [label = "$key = $iter_tmp0->key()"];
  13 [label = "echo $value"];
  14 [label = "$value"];
  15 [label = "$iter_tmp0->key()"];
  16 [label = "$iter_tmp0"];
  17 [label = "$iter_tmp0->current()"];
  18 [label = "<empty>"];
  19 [label = "echo 111"];
  20 [label = "$iter_tmp0"];
  21 [label = "$value = $iter_tmp0->current()"];
  22 [label = "$iter_tmp0"];
  23 [label = "\"arr\""];
  24 [label = "$iter_tmp0->next()"];
  25 [label = "$iter_tmp0"];
  26 [label = "$key"];
  27 [label = "$arr"];
  28 [label = "$_GET[\"arr\"]"];
  29 [label = "RET"];
  30 [label = "$arr = $_GET[\"arr\"]"];
  31 [label = "$value"];
  32 [label = "is_null($value)"];
  33 [label = "$key"];
  34 [label = "$iter_tmp0->key()"];
  35 [label = "<empty>"];
12 -> 5 [label = ""];
18 -> 11 [label = ""];
27 -> 1 [label = ""];
0 -> 17 [label = ""];
22 -> 9 [label = ""];
4 -> 7 [label = ""];
34 -> 4 [label = ""];
23 -> 28 [label = ""];
16 -> 15 [label = ""];
14 -> 13 [label = ""];
17 -> 21 [label = ""];
6 -> 18 [label = ""];
11 -> 19 [label = ""];
7 -> 0 [label = ""];
32 -> 2 [label = ""];
19 -> 29 [label = ""];
30 -> 20 [label = ""];
31 -> 32 [label = ""];
8 -> 33 [label = ""];
1 -> 23 [label = ""];
21 -> 35 [label = ""];
13 -> 25 [label = ""];
2 -> 11 [label = ""];
35 -> 31 [label = ""];
3 -> 8 [label = ""];
25 -> 24 [label = ""];
9 -> 6 [label = ""];
2 -> 14 [label = ""];
26 -> 16 [label = ""];
5 -> 22 [label = ""];
10 -> 34 [label = ""];
28 -> 30 [label = ""];
15 -> 12 [label = ""];
24 -> 26 [label = ""];
33 -> 10 [label = ""];
20 -> 3 [label = ""];
}

Currently, whenFalse returns 12 nodes, while whenTrue returns 6 nodes. This seems quite strange. The expected behavior should be as shown in the following graph (whenTrue returns 13 nodes, while whenFalse returns empty set).

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions