Skip to content

PHP 8.5 compatibility fixes - #540

Merged
develart-projects merged 2 commits into
Shardj:masterfrom
oakimov:php85-compat-fixes
Jun 16, 2026
Merged

develart-projects merged 2 commits into
Shardj:masterfrom
oakimov:php85-compat-fixes

Conversation

@oakimov

@oakimov oakimov commented Jun 12, 2026 •

Copy link
Copy Markdown

Summary

Resolves PHP 8.5 deprecations still present on master. Each category below was confirmed to emit a deprecation on PHP 8.5 before fixing; every changed file passes php -l.

Fix Deprecation (PHP 8.5) Files
DOMDocument::$actualEncoding → ->encoding property removed in 8.1; fatal in 8.5 Zend/Feed/Rss.php, Atom.php, Element.php
?? '' guards for null array offsets / array_key_exists() keys "Using null as an array offset is deprecated" Db/Select.php, Http/Client.php, Form.php, Filter/Input.php, Navigation/Container.php, File/Transfer/Adapter/Http.php, TimeSync.php, Translate/Adapter/Tmx.php
preg_replace(...) ?? $sql so a PCRE-limit failure can't pass null to preg_split() "Passing null to parameter #2 ($subject) ... is deprecated" — fixes #520 Db/Statement.php
imagedestroy() called only on PHP_VERSION_ID < 80000 "deprecated since 8.5, as it has no effect since 8.0" Captcha/Image.php, Barcode/Renderer/Image.php
ReflectionProperty::setAccessible() called only on PHP_VERSION_ID < 80100 "deprecated since 8.5, as it has no effect since 8.1" Wildfire/Plugin/FirePhp.php
Non-canonical cast alias (double) → (float) "Non-canonical cast ... is deprecated" Search/Lucene/Document/Xlsx.php
CodeGenerator default-value arrays: RecursiveArrayIterator + offsetSet-during-iteration (which calls new ArrayIterator($object)) replaced with an explicit recursive helper new ArrayIterator($object) deprecated in 8.5 CodeGenerator/Php/Property/DefaultValue.php

Closes #520.

Notes:

  • The cast-alias change was located with PHP's tokenizer (token_get_all), so only the real cast operator is changed — (boolean)/(integer) appearing in doc comments is intentionally left untouched.
  • The case-statement-semicolon deprecation (case X; → case X:) is already fixed on this fork's master, so it is not part of this PR.

Attribution

These fixes draw on the parallel PHP 8.5 work in the zf1s/zf1 fork — specifically PR #227 (null-as-array-offset guards) and PR #225 (the broader 8.5 sweep). Credit to their authors; this PR ports the equivalent changes to this fork's layout and to what master here still needs. The Db/Statement.php fix follows the approach proposed in #520.

Testing

  • php -l clean on all 17 changed files (PHP 8.5.7).
  • The cast and case-semicolon detection re-runs report 0 remaining (idempotent).
  • The CodeGenerator refactor produces valid output for nested arrays with 0 deprecations.

Resolve PHP 8.5 deprecations still present on master. Each category was
verified to emit a deprecation on PHP 8.5 before fixing.

- Zend_Feed (Rss/Atom/Element): DOMDocument::$actualEncoding was removed
  in PHP 8.1; use ->encoding instead. Affects all RSS/Atom output.
- "Using null as an array offset" (8.5): guard with `?? ''` in
  Zend_Db_Select::columns(), Zend_Http_Client::_setParameter(),
  Zend_Form (_dissolveArrayValue/_attachToArray), Zend_Filter_Input,
  Zend_Navigation_Container (current/getChildren),
  Zend_File_Transfer_Adapter_Http, Zend_TimeSync, Zend_Translate_Adapter_Tmx.
- imagedestroy() (no-op since 8.0, deprecated 8.5): call only on
  PHP_VERSION_ID < 80000 in Zend_Captcha_Image, Zend_Barcode_Renderer_Image.
- ReflectionProperty::setAccessible() (no-op since 8.1, deprecated 8.5):
  call only on PHP_VERSION_ID < 80100 in Zend_Wildfire FirePhp.
- Non-canonical cast alias (deprecated 8.5): (double) -> (float) in
  Zend_Search_Lucene Xlsx (tokenizer-checked; comment text left untouched).
- Zend_CodeGenerator default-value array generation: the
  RecursiveArrayIterator + offsetSet-during-iteration approach calls
  new ArrayIterator($object) (deprecated 8.5); replaced with an explicit
  recursive _prepareArrayValue() helper preserving behaviour.

Credit: the null-as-array-offset guards and the broader 8.5 sweep this
draws from originate in the zf1s/zf1 fork, PR Shardj#227 and Shardj#225 respectively.
The case-statement-semicolon deprecations from Shardj#225 are already fixed on
this fork's master and are not included here.
_stripQuoted() runs three preg_replace() passes to strip quoted literals
before _parseParameters() splits the SQL. On large statements (e.g. a big
IN (?, ?, ...) clause), PCRE can exceed its backtrack limit and
preg_replace() returns null instead of a string; that null then reaches
preg_split() in _parseParameters(), raising "Passing null to parameter Shardj#2
($subject) of type string is deprecated" on PHP 8.1+.

Cast $sql once at the top of _stripQuoted() and fall back to the prior
$sql when a pass returns null (preg_replace(...) ?? $sql), so a failed
pass keeps the last good string and null never propagates.

Fixes Shardj#520.
@oakimov
oakimov marked this pull request as ready for review June 12, 2026 08:23
@develart-projects develart-projects added enhancement New feature or request to be released PR exists or in master, but not released yet labels Jun 16, 2026
@develart-projects develart-projects added this to the 1.25.1 milestone Jun 16, 2026
@develart-projects

Copy link
Copy Markdown
Collaborator

Good job, thank you.

@develart-projects
develart-projects merged commit f0fc088 into Shardj:master Jun 16, 2026
8 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request to be released PR exists or in master, but not released yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

preg_split() deprecation warning in _parseParameters() when preg_replace() returns null in _stripQuoted()

2 participants