summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Boerger <helly@php.net>2006-07-09 10:22:27 +0000
committerMarcus Boerger <helly@php.net>2006-07-09 10:22:27 +0000
commit5fee10735fa87f66089effcab60ecf18d2aae283 (patch)
treeb0d70d454f94f7f08cf1345d4f6ace5f8c4742ea
parent0fd2b9620428898d77ce1b95f77f4073c882c8d1 (diff)
downloadphp-git-5fee10735fa87f66089effcab60ecf18d2aae283.tar.gz
- MFH Add spl_object_hash()
-rwxr-xr-xext/spl/php_spl.c28
-rwxr-xr-xext/spl/tests/spl_005.phpt23
2 files changed, 51 insertions, 0 deletions
diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c
index 07dff83fd9..f22a30c498 100755
--- a/ext/spl/php_spl.c
+++ b/ext/spl/php_spl.c
@@ -36,6 +36,7 @@
#include "spl_observer.h"
#include "zend_exceptions.h"
#include "zend_interfaces.h"
+#include "ext/standard/md5.h"
#ifdef COMPILE_DL_SPL
ZEND_GET_MODULE(spl)
@@ -566,6 +567,32 @@ PHP_FUNCTION(spl_autoload_functions)
add_next_index_string(return_value, EG(autoload_func)->common.function_name, 1);
} /* }}} */
+/* {{{ proto string spl_object_hash(object obj)
+ Return hash id for given object */
+PHP_FUNCTION(spl_object_hash)
+{
+ zval *obj;
+ int len;
+ char *hash;
+ char md5str[33];
+ PHP_MD5_CTX context;
+ unsigned char digest[16];
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &obj) == FAILURE) {
+ return;
+ }
+
+ len = spprintf(&hash, 0, "%p:%d", Z_OBJ_HT_P(obj), Z_OBJ_HANDLE_P(obj));
+
+ md5str[0] = '\0';
+ PHP_MD5Init(&context);
+ PHP_MD5Update(&context, (unsigned char*)hash, len);
+ PHP_MD5Final(digest, &context);
+ make_digest(md5str, digest);
+ RETVAL_STRING(md5str, 1);
+ efree(hash);
+}
+
int spl_build_class_list_string(zval **entry, char **list TSRMLS_DC) /* {{{ */
{
char *res;
@@ -632,6 +659,7 @@ zend_function_entry spl_functions[] = {
PHP_FE(spl_autoload_call, NULL)
PHP_FE(class_parents, NULL)
PHP_FE(class_implements, NULL)
+ PHP_FE(spl_object_hash, NULL)
#ifdef SPL_ITERATORS_H
PHP_FE(iterator_to_array, arginfo_iterator)
PHP_FE(iterator_count, arginfo_iterator)
diff --git a/ext/spl/tests/spl_005.phpt b/ext/spl/tests/spl_005.phpt
new file mode 100755
index 0000000000..bb297bb6bc
--- /dev/null
+++ b/ext/spl/tests/spl_005.phpt
@@ -0,0 +1,23 @@
+--TEST--
+SPL: spl_object_hash()
+--SKIPIF--
+<?php if (!extension_loaded("spl")) print "skip"; ?>
+--FILE--
+<?php
+
+var_dump(spl_object_hash(new stdClass));
+var_dump(spl_object_hash(42));
+var_dump(spl_object_hash());
+
+?>
+===DONE===
+<?php exit(0); ?>
+--EXPECTF--
+string(32) "%s"
+
+Warning: spl_object_hash() expects parameter 1 to be object, integer given in %sspl_005.php on line %d
+NULL
+
+Warning: spl_object_hash() expects exactly 1 parameter, 0 given in %sspl_005.php on line %d
+NULL
+===DONE===