Skip to content

Conversation

@fredden
Copy link
Member

@fredden fredden commented Dec 23, 2025

Description

While investigating the cause of a PHP Fatal error while processing some input in the PSR12.Functions.ReturnTypeDeclaration sniff, I noticed that the File::getMethodProperties() method did not return sensible values in for some parse errors. The input file in question was
src/Standards/Generic/Tests/Arrays/DisallowLongArraySyntaxUnitTest.2.inc, which contains an intentional parse error. The File::getMethodProperties() method claimed that the return type of the test function was << HEAD, which is nonsense.

The change in this commit safeguards from such parse errors and resolves the issue that was being encountered downstream in the sniff.

Suggested changelog entry

Handle parse error in File::getMethodProperties()

Related issues/external references

Relates to #152

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
    • This change is only breaking for integrators, not for external standards or end-users.
  • Documentation improvement

PR checklist

  • I have checked there is no other PR open for the same change.
  • I have read the Contribution Guidelines.
  • I grant the project the right to include and distribute the code under the BSD-3-Clause license (and I have the right to grant these rights).
  • I have added tests to cover my changes.
  • I have verified that the code complies with the projects coding standards.
  • [Required for new sniffs] I have added XML documentation for the sniff.
  • I have opened a sister-PR in the documentation repository to update the Wiki.

While investigating the cause of a PHP Fatal error while processing some input
in the `PSR12.Functions.ReturnTypeDeclaration` sniff, I noticed that the
`File::getMethodProperties()` method did not return sensible values in for some
parse errors. The input file in question was
`src/Standards/Generic/Tests/Arrays/DisallowLongArraySyntaxUnitTest.2.inc`,
which contains an intentional parse error. The `File::getMethodProperties()`
method claimed that the return type of the `test` function was `<< HEAD`, which
is nonsense.

The change in this commit safeguards from such parse errors and resolves the
issue that was being encountered downstream in the sniff.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant