diff --git a/phpseclib/Crypt/RSA.php b/phpseclib/Crypt/RSA.php
index 15aab4ab..dfc82bb6 100644
--- a/phpseclib/Crypt/RSA.php
+++ b/phpseclib/Crypt/RSA.php
@@ -1478,9 +1478,14 @@ class Crypt_RSA
$this->components = array();
$xml = xml_parser_create('UTF-8');
- xml_set_object($xml, $this);
- xml_set_element_handler($xml, '_start_element_handler', '_stop_element_handler');
- xml_set_character_data_handler($xml, '_data_handler');
+ if (version_compare(PHP_VERSION, '8.4.0', '>=')) {
+ xml_set_element_handler($xml, array($this, '_start_element_handler'), array($this, '_stop_element_handler'));
+ xml_set_character_data_handler($xml, array($this, '_data_handler'));
+ } else {
+ xml_set_object($xml, $this);
+ xml_set_element_handler($xml, '_start_element_handler', '_stop_element_handler');
+ xml_set_character_data_handler($xml, '_data_handler');
+ }
// add to account for "dangling" tags like ... that are sometimes added
if (!xml_parse($xml, '' . $key . '')) {
xml_parser_free($xml);