Skip to content

PHP8.4: Replace xml_set_object() with callable arrays in Translate ad…#534

Merged
develart-projects merged 2 commits intoShardj:masterfrom
geoalexidis:php84/fix-xml-set-object-deprecation
Mar 25, 2026
Merged

PHP8.4: Replace xml_set_object() with callable arrays in Translate ad…#534
develart-projects merged 2 commits intoShardj:masterfrom
geoalexidis:php84/fix-xml-set-object-deprecation

Conversation

@geoalexidis
Copy link
Copy Markdown

@geoalexidis geoalexidis commented Mar 25, 2026

Fix PHP 8.4 deprecation: replace xml_set_object() with callable arrays in Translate adapters

Summary

PHP 8.4 deprecated xml_set_object() (PHP RFC), causing deprecation warnings when using any of the XML-based translation adapters. This PR removes the deprecated call across all affected adapters and replaces string-based method references with proper callable arrays.

Changes

Removed xml_set_object($parser, $this) and updated the string method names passed to xml_set_element_handler() and xml_set_character_data_handler() to use [$this, '_methodName'] callables in:

  • library/Zend/Translate/Adapter/Tmx.php
  • library/Zend/Translate/Adapter/Tbx.php
  • library/Zend/Translate/Adapter/Qt.php
  • library/Zend/Translate/Adapter/Xliff.php
  • library/Zend/Translate/Adapter/XmlTm.php

Before:

xml_set_object($this->_file, $this);
xml_set_element_handler($this->_file, "_startElement", "_endElement");
xml_set_character_data_handler($this->_file, "_contentElement");

After:

xml_set_element_handler($this->_file, [$this, '_startElement'], [$this, '_endElement']);
xml_set_character_data_handler($this->_file, [$this, '_contentElement']);

Backwards Compatibility

This change is fully backwards compatible:

  • Callable arrays ([$object, 'method']) have been valid since PHP 5.3.0 — well before any PHP version this library targets.
  • The xml_set_*_handler() functions have accepted any valid PHP callable (including callable arrays) since PHP 4. Passing a callable array was always the more correct approach; xml_set_object() was merely a convenience that allowed passing bare strings as shorthand.
  • xml_set_object() is deprecated in PHP 8.4, not removed. Existing installations on PHP ≤ 8.3 are unaffected by this change in behaviour; they simply no longer emit the deprecation notice.
  • No public API, interface, or behaviour is altered — only the internal wiring of the XML parser callbacks.

Testing

Existing unit tests for the affected adapters cover this change. No new tests are required as the observable behaviour is identical.

…apters

Remove deprecated xml_set_object() from Tmx, Tbx, Qt, Xliff, and XmlTm
adapters, replacing string method references with [$this, '_method']
callables. No public API or behaviour changed.
@sreichel
Copy link
Copy Markdown

... composer run-script phpstan:baseline ...

@geoalexidis geoalexidis force-pushed the php84/fix-xml-set-object-deprecation branch from 3763694 to 0148584 Compare March 25, 2026 12:31
@geoalexidis
Copy link
Copy Markdown
Author

Hi @develart-projects

PR is ready for review.

Thanks @sreichel for the phpstan support.

@develart-projects develart-projects added enhancement New feature or request to be released PR exists or in master, but not released yet labels Mar 25, 2026
@develart-projects develart-projects added this to the 1.25.1 milestone Mar 25, 2026
@develart-projects develart-projects merged commit f4c539f into Shardj:master Mar 25, 2026
8 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.

4 participants