Skip to content

fix: prevent assert string evaluation in REST controller on PHP 7#412

Open
imantsk wants to merge 1 commit into
core-betafrom
fix/php-7-compat
Open

fix: prevent assert string evaluation in REST controller on PHP 7#412
imantsk wants to merge 1 commit into
core-betafrom
fix/php-7-compat

Conversation

@imantsk

@imantsk imantsk commented Jun 20, 2026

Copy link
Copy Markdown
Member

Summary

On PHP 7.x with assertions active, assert() evaluates a string first argument as PHP code. REST_Controller::__construct() passed static::BASE_ROUTE (a route string) directly to assert(), so PHP tried to execute each route value as code.

Reported from a live PHP 7.4 site: every registered REST controller emitted warnings — Use of undefined constant recently/active/import/plugins/file/upload, A non-numeric value encountered (recently-active parsed as subtraction), and Division by zero (routes containing /).

PHP 8 removed string evaluation in assert(), so this only affects PHP 7.x.

Change

assert( static::BASE_ROUTE !== '', get_class( $this ) . '::BASE_ROUTE must be set' );

A boolean first argument is never evaluated as a string, on any PHP version, and preserves the original intent. The sibling Model::__construct() assert is unaffected — its argument is an array, not a string.

Verification

  • phpcs clean, php -l clean.
  • REST test suite: 47/47 pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant