Skip to content

Add check: runtime fatal-error prevention in PHP plugin code #1273

Description

@davidperezgar

Summary

Add a check to detect high-risk patterns that commonly cause runtime fatals in plugins.

Why

Parse-error checks are useful, but many production fatals come from runtime assumptions (missing functions/classes/files/callbacks).

Proposed detection

Flag risky cases such as:

  1. require / require_once on dynamic or unguarded paths (without file_exists/is_readable nearby).
  2. Calling plugin/theme integration functions without function_exists guard.
  3. Instantiating optional classes without class_exists guard.
  4. Invoking dynamic callbacks without is_callable.
  5. Hooking callbacks that may not exist (array/class method) without method_exists / class guard.

Acceptance criteria

  1. Reports file + line.
  2. Provides actionable remediation guidance in message.
  3. Includes false-positive controls for clearly safe patterns.
  4. Includes tests for positive and negative cases.

Inspired by

Internal Scanner checks around parse/safety, especially phpcs_parse_errors.

Metadata

Metadata

Assignees

Labels

ChecksAudit/test of the particular part of the plugin

Fields

No fields configured for Enhancement.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions