~ubuntu-branches/ubuntu/wily/phabricator/wily

« back to all changes in this revision

Viewing changes to src/lint/linter/__tests__/xhpast/reused-local.lint-test

  • Committer: Package Import Robot
  • Author(s): Richard Sellam
  • Date: 2014-11-01 23:20:06 UTC
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: package-import@ubuntu.com-20141101232006-mvlnp0cil67tsboe
Tags: upstream-0~git20141101/arcanist
Import upstream version 0~git20141101, component arcanist

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
function f($stuff, $thing) {
 
4
  foreach ($stuff as $ii) {}
 
5
 
 
6
  // OK: Only reused for iteration.
 
7
 
 
8
  foreach ($stuff as $ii) {}
 
9
}
 
10
 
 
11
function g($stuff, $thing) {
 
12
  foreach ($stuff as $thing) {}
 
13
 
 
14
  // OK: Not reused later.
 
15
}
 
16
 
 
17
function h($stuff, $thing) {
 
18
 
 
19
  // OK: Used afterwards but not before.
 
20
 
 
21
  foreach ($stuff as $key => $val) {}
 
22
 
 
23
  $key = 1;
 
24
  $thing = 1;
 
25
  $thing = $key;
 
26
  $key = $thing;
 
27
}
 
28
 
 
29
function i($stuff, $thing) {
 
30
  foreach ($stuff as $thing) {
 
31
    $thing++;
 
32
  }
 
33
 
 
34
  // OK: Used afterwards but inside loop.
 
35
 
 
36
  foreach ($stuff as $thing) {
 
37
    $thing++;
 
38
  }
 
39
}
 
40
 
 
41
function j($stuff, $thing) {
 
42
 
 
43
  foreach ($stuff as $thing) {
 
44
    break;
 
45
  }
 
46
 
 
47
  // ERROR: Clobbers $thing; probably not what the author intended.
 
48
 
 
49
  f($thing);
 
50
}
 
51
 
 
52
function k($stuff, $thing) {
 
53
  foreach ($stuff as $thing) {
 
54
    break;
 
55
  }
 
56
 
 
57
  // ERROR: Clobbers $thing. Test case to cover some errors of implementation
 
58
  // where subsequent legitimate foreach()es threw a wrench in the gears.
 
59
 
 
60
  f($thing);
 
61
 
 
62
  $other = array();
 
63
  foreach ($other as $item) {}
 
64
}
 
65
 
 
66
~~~~~~~~~~
 
67
error:43:22
 
68
error:53:22