diff --git a/NEWS b/NEWS index 20a3fb4bb77fd..401979b469383 100644 --- a/NEWS +++ b/NEWS @@ -51,6 +51,10 @@ PHP NEWS - Sodium: . New cryptographic extension +- SPL: + . Added spl_object_id() function returning an integer (the object handle) for an object. + (Tyson Andre) + - SQLite3: . Fixed bug #74883 (SQLite3::__construct() produces "out of memory" exception with invalid flags). (Anatol) diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 34b54e81e1ddb..2925c400dd135 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -794,6 +794,20 @@ PHP_FUNCTION(spl_object_hash) } /* }}} */ +/* {{{ proto int spl_object_id(object obj) + Returns the integer object handle for the given object */ +PHP_FUNCTION(spl_object_id) +{ + zval *obj; + + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_OBJECT(obj) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_NULL()); + + RETURN_LONG((zend_long)Z_OBJ_HANDLE_P(obj)); +} +/* }}} */ + PHPAPI zend_string *php_spl_object_hash(zval *obj) /* {{{*/ { intptr_t hash_handle, hash_handlers; @@ -915,6 +929,10 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_spl_object_hash, 0, 0, 1) ZEND_ARG_INFO(0, obj) ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_spl_object_id, 0, 0, 1) + ZEND_ARG_INFO(0, obj) +ZEND_END_ARG_INFO() /* }}} */ /* {{{ spl_functions @@ -931,6 +949,7 @@ const zend_function_entry spl_functions[] = { PHP_FE(class_implements, arginfo_class_implements) PHP_FE(class_uses, arginfo_class_uses) PHP_FE(spl_object_hash, arginfo_spl_object_hash) + PHP_FE(spl_object_id, arginfo_spl_object_id) #ifdef SPL_ITERATORS_H PHP_FE(iterator_to_array, arginfo_iterator_to_array) PHP_FE(iterator_count, arginfo_iterator) diff --git a/ext/spl/tests/spl_object_id.phpt b/ext/spl/tests/spl_object_id.phpt new file mode 100644 index 0000000000000..e316bd01f93fc --- /dev/null +++ b/ext/spl/tests/spl_object_id.phpt @@ -0,0 +1,24 @@ +--TEST-- +SPL: spl_object_id() +--FILE-- + +===DONE=== + +--EXPECTF-- +int(%d) + +Warning: spl_object_id() expects parameter 1 to be object, integer given in %sspl_object_id.php on line %d +NULL + +Warning: spl_object_id() expects exactly 1 parameter, 0 given in %sspl_object_id.php on line %d +NULL +bool(false) +===DONE===
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: