Skip to content

PHP 8.5 Compatibility: Deprecated Method SplObjectStorage::attach() called in HtmlMin.php #137

Description

@Sukanyeah

PHP 8.5 Compatibility: Deprecated Method SplObjectStorage::attach() called in HtmlMin.php

The Problem/Requirement

When running voku/html-min under the modern PHP 8.5 runtime environment, the engine flags a deprecation warning that disrupts execution execution streams. Specifically, the package utilizes SplObjectStorage::attach() on line 352 of HtmlMin.php, which has been officially deprecated since PHP 8.5 in favor of the standardized SplObjectStorage::offsetSet() method pattern.

In strict development setups or environments configured to convert engine notices/warnings into exceptions, this deprecation results in fatal runtime disruptions (such as HTTP 500 responses) across multiple application layout renders.

The Solution

Update the method call inside the storage lifecycle handler to use the modern, forward-compatible syntax.

-  $this->domLoopObservers->attach($object);
+  $this->domLoopObservers->offsetSet($object);

This structural modification entirely eliminates the deprecation alert stream under PHP 8.5 while preserving transparent backward compatibility for users running older versions of PHP 8.x.

Alternatives considered

Silencing the error stream via runtime error_reporting() configuration bypasses was evaluated. However, addressing the root architectural syntax directly within the source codebase is the optimal long-term path to prepare the package for the eventual removal of the legacy attach() signature in upcoming major PHP releases.

Additional context

Environment Details:

  • PHP Version: 8.5.x
  • Package Version: voku/html-min (Latest release)

Full Error Stack Trace:

Deprecated: Method SplObjectStorage::attach() is deprecated since 8.5, use method SplObjectStorage::offsetSet() instead in src/voku/helper/HtmlMin.php on line 352

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions