Skip to content

fix: resolve PHP 8.4/8.5 deprecations in HttpAsset and BasePhpFormulaLoader#47

Merged
LukeTowers merged 2 commits into
assetic-php:masterfrom
austinderrick:fix/php-84-85-deprecations
Jun 4, 2026
Merged

fix: resolve PHP 8.4/8.5 deprecations in HttpAsset and BasePhpFormulaLoader#47
LukeTowers merged 2 commits into
assetic-php:masterfrom
austinderrick:fix/php-84-85-deprecations

Conversation

@austinderrick

@austinderrick austinderrick commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Summary

A full PHPUnit run under PHP 8.4.14 and PHP 8.5.5 with error_reporting=-1 surfaced two deprecations originating in the library's own src/ (everything else came from twig/scssphp in vendor/). This PR fixes both, plus one latent type-hint bug found along the way.

1. HttpAsset::getLastModified()$http_response_header deprecated (PHP 8.5)

The predefined locally scoped $http_response_header variable is deprecated in 8.5. The existing function_exists('http_get_last_response_headers') shim does not suppress it: the notice is emitted at compile time from the bare variable read — verified with php -l, which executes nothing yet still emits it — so a runtime guard can never silence it.

Reading it through the null-coalescing operator ($http_response_header ?? []) compiles to a non-deprecated fetch, so the pre-8.4 fallback keeps working while 8.5 emits nothing. ?? [] (not ?? null) keeps the subsequent foreach safe. composer.json still pins php: ^7.3 || ^8.0, so the legacy branch can't be dropped outright yet — the comment notes when it can.

2. BasePhpFormulaLoader::processCall()null to unserialize() (PHP 8.4 & 8.5)

shell_exec() returns string|false|null; passing null to unserialize()'s non-nullable string parameter is deprecated in 8.4+. Guarded with is_string(). The array() fallback is behaviour-identical to the previous unserialize(false) === false path (the downstream isset($args[0..2]) checks read false on an empty array).

3. CssImportFilter — missing use (latent, any PHP version)

The constructor's ?FilterInterface hint resolved to a non-existent Assetic\Filter\FilterInterface instead of the real Assetic\Contracts\Filter\FilterInterface (no matching import) — a latent Error whenever a non-null filter is passed. Added the missing use.

…Loader

A full PHPUnit run under PHP 8.4 and 8.5 (error_reporting=-1) surfaced two
deprecations originating in the library's own src/:

- HttpAsset::getLastModified() — the predefined locally scoped
  $http_response_header variable is deprecated in PHP 8.5. The existing
  function_exists('http_get_last_response_headers') shim does not suppress it:
  the notice is emitted at compile time from the bare variable read (verified
  via `php -l`, which executes nothing yet still emits it), so a runtime guard
  can never silence it. Reading it through the null-coalescing operator
  (`$http_response_header ?? []`) compiles to a non-deprecated fetch, keeping
  the pre-8.4 fallback working while emitting nothing on 8.5. `?? []` (not null)
  keeps the subsequent foreach safe. composer still pins php ^7.3 || ^8.0, so
  the legacy branch cannot be removed outright yet.

- BasePhpFormulaLoader::processCall() — shell_exec() returns string|false|null,
  and passing null to unserialize()'s non-nullable string parameter is
  deprecated in PHP 8.4+. Guard with is_string(); the array() fallback is
  behaviour-identical to the previous unserialize(false) === false path.

Also add the missing `use Assetic\Contracts\Filter\FilterInterface;` to
CssImportFilter so the constructor's ?FilterInterface type hint resolves to the
real interface instead of a non-existent Assetic\Filter\FilterInterface (a
latent Error on any PHP version when a non-null filter is passed).

Verified: zero project-src deprecations on PHP 8.4.14 and 8.5.5; the test suite
remains green (HttpAsset, FormulaLoader and CssImportFilter tests all pass).
Comment thread src/Assetic/Factory/Loader/BasePhpFormulaLoader.php Outdated
Co-authored-by: Jack Wilkinson <31214002+jaxwilko@users.noreply.github.com>
@LukeTowers LukeTowers merged commit 3ce34db into assetic-php:master Jun 4, 2026
7 checks passed
bennothommo pushed a commit that referenced this pull request Jun 15, 2026
Adds 8.4 and 8.5 to the unit test matrix, now that #45 and #47 have
cleaned up Assetic's own deprecations on those versions.

The only deprecations remaining on 8.4/8.5 originate in vendor code
(Twig 2.x and ScssPhp 1.x) that Assetic cannot fix, so the
symfony/phpunit-bridge deprecation helper is configured to tolerate
indirect (vendor-internal) deprecations while still failing the build
on any deprecation in Assetic's own code (max[self]=0&max[direct]=0).
The full suite passes on 8.4 and 8.5 (408 tests, 547 assertions).

Also bumps the actions pinned to the deprecated Node 20 runtime to
their Node 24 releases: actions/checkout v4 -> v5 and
supplypike/setup-bin v4 -> v5. shivammathur/setup-php@v2 already runs
on Node 24, so it is left unchanged.
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.

3 participants