Commit 2c1c61de079 for php.net
commit 2c1c61de07953f901d95fd93e3ce79b50032e65c
Author: Gina Peter Banyard <girgias@php.net>
Date: Sun Aug 9 21:10:20 2026 +0100
spl: deprecate spl_object_hash()
RFC: https://wiki.php.net/rfc/deprecations_php_8_6#deprecate_spl_object_hash
diff --git a/Zend/tests/bug60598.phpt b/Zend/tests/bug60598.phpt
index ae5914ed3fe..729a4cfd7f8 100644
--- a/Zend/tests/bug60598.phpt
+++ b/Zend/tests/bug60598.phpt
@@ -11,11 +11,11 @@ class ObjectOne {
public function __construct() {
global $containers;
$this->guid = 1;
- $containers[spl_object_hash($this)] = $this;
+ $containers[spl_object_id($this)] = $this;
}
public function __destruct() {
global $containers;
- $containers[spl_object_hash($this)] = NULL;
+ $containers[spl_object_id($this)] = NULL;
}
}
diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c
index e80917a7706..36be19ed399 100644
--- a/ext/spl/php_spl.c
+++ b/ext/spl/php_spl.c
@@ -16,11 +16,15 @@
#include <config.h>
#endif
+#include "php_spl.h"
+#include "zend_attributes.h"
+#include "php_spl_arginfo.h"
+#include "zend_autoload.h"
+#include "zend_exceptions.h"
+#include "zend_interfaces.h"
#include "php.h"
#include "php_main.h"
#include "ext/standard/info.h"
-#include "php_spl.h"
-#include "php_spl_arginfo.h"
#include "spl_functions.h"
#include "spl_array.h"
#include "spl_directory.h"
@@ -30,9 +34,6 @@
#include "spl_dllist.h"
#include "spl_fixedarray.h"
#include "spl_heap.h"
-#include "zend_autoload.h"
-#include "zend_exceptions.h"
-#include "zend_interfaces.h"
ZEND_TLS zend_string *spl_autoload_extensions;
@@ -552,6 +553,7 @@ PHP_MINIT_FUNCTION(spl)
PHP_MINIT(spl_fixedarray)(INIT_FUNC_ARGS_PASSTHRU);
PHP_MINIT(spl_observer)(INIT_FUNC_ARGS_PASSTHRU);
+ register_php_spl_symbols(module_number);
return SUCCESS;
}
/* }}} */
diff --git a/ext/spl/php_spl.stub.php b/ext/spl/php_spl.stub.php
index d3b5d44f11d..814a5db9bd9 100644
--- a/ext/spl/php_spl.stub.php
+++ b/ext/spl/php_spl.stub.php
@@ -42,6 +42,7 @@ function spl_autoload_unregister(callable $callback): bool {}
function spl_classes(): array {}
/** @refcount 1 */
+#[\Deprecated(message: "consider using spl_object_id() instead", since: "8.6")]
function spl_object_hash(object $object): string {}
function spl_object_id(object $object): int {}
diff --git a/ext/spl/php_spl_arginfo.h b/ext/spl/php_spl_arginfo.h
index 8b0ea4b7245..e9e34434479 100644
Binary files a/ext/spl/php_spl_arginfo.h and b/ext/spl/php_spl_arginfo.h differ
diff --git a/ext/spl/tests/SplObjectStorage/concurrent_deletion.phpt b/ext/spl/tests/SplObjectStorage/concurrent_deletion.phpt
index a4b4e7d3a98..285945616e9 100644
--- a/ext/spl/tests/SplObjectStorage/concurrent_deletion.phpt
+++ b/ext/spl/tests/SplObjectStorage/concurrent_deletion.phpt
@@ -12,7 +12,7 @@ public function getHash($obj): string {
if ($this->mutate) {
$victim[new stdClass()] = null;
}
- return spl_object_hash($obj);
+ return spl_object_id($obj);
}
}
diff --git a/ext/spl/tests/spl_object_hash_deprecated.phpt b/ext/spl/tests/spl_object_hash_deprecated.phpt
new file mode 100644
index 00000000000..a2aae7fa869
--- /dev/null
+++ b/ext/spl/tests/spl_object_hash_deprecated.phpt
@@ -0,0 +1,12 @@
+--TEST--
+spl_object_hash(): is deprecated
+--FILE--
+<?php
+
+$o = new stdClass();
+var_dump(spl_object_hash($o));
+
+?>
+--EXPECTF--
+Deprecated: Function spl_object_hash() is deprecated since 8.6, consider using spl_object_id() instead in %s on line %d
+string(32) "00000000000000010000000000000000"