Skip to content

fix: Improve compatibility with PHP 8.5#484

Open
matsuo wants to merge 2 commits into
ezyang:masterfrom
matsuo:update-for-php85
Open

fix: Improve compatibility with PHP 8.5#484
matsuo wants to merge 2 commits into
ezyang:masterfrom
matsuo:update-for-php85

Conversation

@matsuo
Copy link
Copy Markdown
Contributor

@matsuo matsuo commented May 11, 2026

This PR addresses the following two issues to improve compatibility with PHP 8.5 and ensure that CI jobs pass on PHP 8.5.

The following deprecated messages were displayed when running tests/index.php in the htmlpurifier repository using PHP 8.5.

% /opt/homebrew/opt/php@8.5/bin/php tests/index.php
All HTML Purifier tests on PHP 8.5.2
Exception 1!
Unexpected PHP Error [Using null as an array offset is deprecated, use an empty string instead] severity [8192] in [/tmp/htmlpurifier/library/HTMLPurifier/URISchemeRegistry.php line 55]
	in testDefaultSchemeNull
	in HTMLPurifier_AttrDef_URITest
Exception 2!
Unexpected PHP Error [Using null as an array offset is deprecated, use an empty string instead] severity [8192] in [/tmp/htmlpurifier/library/HTMLPurifier/URISchemeRegistry.php line 58]
	in testDefaultSchemeNull
	in HTMLPurifier_AttrDef_URITest
Exception 3!
Unexpected PHP Error [Method SplObjectStorage::attach() is deprecated since 8.5, use method SplObjectStorage::offsetSet() instead] severity [8192] in [/tmp/htmlpurifier/library/HTMLPurifier/Injector/RemoveSpansWithoutAttributes.php line 77]
	in testSingleSpan
	in HTMLPurifier_Injector_RemoveSpansWithoutAttributesTest
Exception 4!
Unexpected PHP Error [Method SplObjectStorage::contains() is deprecated since 8.5, use method SplObjectStorage::offsetExists() instead] severity [8192] in [/tmp/htmlpurifier/library/HTMLPurifier/Injector/RemoveSpansWithoutAttributes.php line 88]
	in testSingleSpanWithAttributes
	in HTMLPurifier_Injector_RemoveSpansWithoutAttributesTest

(snip)

Exception 23!
Unexpected PHP Error [Method SplObjectStorage::detach() is deprecated since 8.5, use method SplObjectStorage::offsetUnset() instead] severity [8192] in [/tmp/htmlpurifier/library/HTMLPurifier/Injector/RemoveSpansWithoutAttributes.php line 89]
	in testDeeplyNestedSpan
	in HTMLPurifier_Injector_RemoveSpansWithoutAttributesTest

(snip)

Thank you.

@matsuo matsuo changed the title Improve compatibility with PHP 8.5 fix: Improve compatibility with PHP 8.5 May 11, 2026
@ezyang ezyang requested a review from Copilot May 11, 2026 12:21
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request aims to eliminate PHP 8.5 deprecation notices observed when running the test suite, improving forward compatibility of HTMLPurifier’s URI handling and an injector’s internal bookkeeping.

Changes:

  • Updates RemoveSpansWithoutAttributes to use SplObjectStorage::offsetSet/offsetExists/offsetUnset instead of deprecated attach/contains/detach.
  • Adds an early-return in URISchemeRegistry::getScheme() intended to avoid “null as an array offset” deprecations on PHP 8.5.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
library/HTMLPurifier/URISchemeRegistry.php Adds a guard intended to prevent PHP 8.5 null-array-offset deprecations during scheme lookup.
library/HTMLPurifier/Injector/RemoveSpansWithoutAttributes.php Replaces deprecated SplObjectStorage methods with the recommended offset* equivalents.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread library/HTMLPurifier/URISchemeRegistry.php Outdated
…t is deprecated, use an empty string instead" in PHP 8.5 (ezyang#483)
@matsuo matsuo force-pushed the update-for-php85 branch from 8147c4c to 43674d5 Compare May 11, 2026 13:06
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.

2 participants