Skip to content

Avoid PHP 8.6 deprecations of the "is" identifier - #105

Open
Roman3349 wants to merge 3 commits into
hamcrest:masterfrom
Roman3349:php86-is
Open

Roman3349 wants to merge 3 commits into
hamcrest:masterfrom
Roman3349:php86-is

Conversation

@Roman3349

Copy link
Copy Markdown

Fixes #104

PHP 8.6 deprecates using is as the name of a class or a function, so loading Hamcrest\Core\Is or the global is() function emits a deprecation notice. This PR keeps both working for backward compatibility, but makes it possible to avoid them.

Changes

  • Hamcrest\Core\IsMatcher is the new name of the Is matcher. Matchers::is() and the global is() now return it. Hamcrest\Core\Is stays as a deprecated subclass of IsMatcher, so existing code keeps working. It is only autoloaded (and so only emits the deprecation) when something references it directly.
  • The global is() function cannot be declared without a deprecation on PHP 8.6, so the generator now writes it into its own file, hamcrest/HamcrestIs.php. The other functions move to hamcrest/HamcrestFunctions.php (the old Hamcrest.php without is(); git diff -C shows it as a copy).
  • hamcrest/Hamcrest.php is now a small loader that requires both files, so code that requires it directly behaves as before.
  • Util::registerGlobalFunctions() gets an optional $includeIs = true parameter. registerGlobalFunctions(false) registers everything except is(), and Matchers::is() can be used instead. The README documents this.
  • CI: added PHP 8.6 to the test matrix.

Testing

The test suite passes on PHP 8.2, 8.5 and 8.6. On PHP 8.6 the only remaining deprecation comes from tests/bootstrap.php, which still registers is() on purpose so the global function stays covered. The test for the deprecated Is class is skipped on PHP 8.6 for the same reason.

Signed-off-by: Roman Ondráček <mail@romanondracek.cz>
Signed-off-by: Roman Ondráček <mail@romanondracek.cz>
Signed-off-by: Roman Ondráček <mail@romanondracek.cz>
@reedy

reedy commented Nov 28, 2026

Copy link
Copy Markdown

Thanks!

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.

PHP8.6: Use of Is as an identifier is deprecated

2 participants