Skip to content

Commit 0fd1786

Browse files
committed
Improve check_refs
Handle manual anchor. Return exit code.
1 parent 883396e commit 0fd1786

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

spec/07-variables.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ Since undefined local variables are not defined implicitly, they stay undefined.
153153

154154
*byRef Context*
155155

156-
If the undefined variable is used in a [byRef context](04-basic-concepts#byRef) then PHP defines the variable implicitly. Hence, a VSlot is created for it and `NULL` is stored in it. A notice is *not* emitted in such a case.
156+
If the undefined variable is used in a byRef context then PHP defines the variable implicitly. Hence, a VSlot is created for it and `NULL` is stored in it. A notice is *not* emitted in such a case.
157157

158158
*Examples of Undefined Variables*
159159

tools/check_refs.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,18 @@
1010
$fullAnchor = $fileName . '#' . $info['anchor'];
1111
$anchors[$fullAnchor] = true;
1212
}
13+
14+
// Collect manual anchors as well
15+
if (preg_match_all('/<a name="([^"]+)">/', $contents, $matches)) {
16+
foreach ($matches[1] as $anchor) {
17+
$fullAnchor = $fileName . '#' . $anchor;
18+
$anchors[$fullAnchor] = true;
19+
}
20+
}
1321
}
1422

1523
// Find unknown anchor references
24+
$foundUnknown = false;
1625
foreach (spec_files() as $fileName => $path) {
1726
$contents = file_get_contents($path);
1827

@@ -33,7 +42,10 @@
3342
}
3443

3544
if (!isset($anchors[$anchor])) {
45+
$foundUnknown = true;
3646
echo "Unknown anchor $anchor in $fileName\n";
3747
}
3848
}
3949
}
50+
51+
exit($foundUnknown ? 1 : 0);

0 commit comments

Comments
 (0)