Skip to content

Commit b3f890f

Browse files
committed
oldClassConstructors: implement a checker
1 parent eb31c2d commit b3f890f

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

classes/tests/critical.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class critical {
2929
'reservedNames',
3030
'deprecatedFunctions',
3131
'newOperatorWithReference',
32+
'oldClassConstructors',
3233
];
3334

3435
/**
@@ -133,5 +134,30 @@ public function _newOperatorWithReference($line) {
133134
}
134135
return false;
135136
}
137+
138+
public function _oldClassConstructors($line) {
139+
static $lastClassName = false;
140+
141+
// reset the name of the class that we've seen
142+
if ($line === '<?php') {
143+
$lastClassName = false;
144+
}
145+
146+
// find the start of PHP class declaration
147+
if (strpos($line, 'class') === 0) {
148+
if (preg_match('#class (\w+)#', $line, $matches)) {
149+
$lastClassName = $matches[1];
150+
}
151+
}
152+
153+
// is the class name used as the function name?
154+
if ($lastClassName !== false && strpos($line, 'function') !== false) {
155+
if (preg_match("#function {$lastClassName}\s?\(#", $line)) {
156+
return true;
157+
}
158+
}
159+
160+
return false;
161+
}
136162
}
137163
?>

0 commit comments

Comments
 (0)