Whole file
terryyin/lizard
The author described this change as “Fix issue #442: PHP use function statements no longer override function names”. It counts as a record because the checks below fail on the code as it stood at ec9ba1ecd and pass on 1700bd91b, with nothing else changed between the two runs.
Projectterryyin/lizard
Fix saved2026-01-16
Sharing licenceMIT · LICENSE.txt
Change size+10 −2
What the code was meant to do, written into the code itself as a save note
Fix issue #442: PHP use function statements no longer override function names
The change
| 29 | 29 | self.assignments = [] | |
| 30 | 30 | self.in_match = False | |
| 31 | 31 | self.match_case_count = 0 | |
| 32 | + | self.in_use_statement = False | |
| 32 | 33 | ||
| 33 | 34 | def _state_global(self, token): | |
| 34 | - | if token == 'class': | |
| 35 | + | if token == 'use': | |
| 36 | + | # Enter use statement mode | |
| 37 | + | self.in_use_statement = True | |
| 38 | + | elif token == ';': | |
| 39 | + | # End of use statement or any other statement | |
| 40 | + | self.in_use_statement = False | |
| 41 | + | elif token == 'class': | |
| 35 | 42 | self._state = self._class_declaration | |
| 36 | 43 | elif token == 'trait': | |
| 37 | 44 | self._state = self._trait_declaration | |
| 38 | - | elif token == 'function': | |
| 45 | + | elif token == 'function' and not self.in_use_statement: | |
| 46 | + | # Only treat 'function' as function declaration if not in use statement | |
| 39 | 47 | self.is_function_declaration = True | |
| 40 | 48 | self._state = self._function_name | |
| 41 | 49 | elif token == 'fn': |
The check that tells the two apart
fail→pass·test/test_languages/testPHP.py::Test_parser_for_PHP::test_multiple_use_function_statements
fail→pass·test/test_languages/testPHP.py::Test_parser_for_PHP::test_use_function_statement_does_not_override_function_name
Check file test/test_languages/testPHP.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before itec9ba1ecd2bcf35118a3662c939ab5643c6e80db
Broken version dated2026-01-16
Modulelizard_languages.php
Units changedPHPLanguageStates
Fingerprint05504fedcff2c179
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.
Other bugs found in terryyin/lizard
- 2026-08-08fix(java): do not report control structures as methods
- 2026-07-02HalsteadClassifier
- 2026-07-02fix(csv): emit columns for extensions with multiple FUNCTION_INFO fields
- 2026-06-15fix(golike): register generic functions with [...] type params
- 2026-06-15fix(java): enhance parsing of generic and qualified type names in anonymous classes
- 2026-06-11fix(script): stop a '#' comment continuing past a trailing backslash (#317)