Skip to content

Implement a POC for spl_object_id(object $x) : int #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ PHP NEWS
(Anatol)

- SPL:
. Added spl_object_id() function returning an integer (the object handle) for an object.
(Tyson Andre)
. Fixed bug #73471 (PHP freezes with AppendIterator). (jhdxr)
. Fixed bug #71412 (Incorrect arginfo for ArrayIterator::__construct).
(tysonandre775 at hotmail dot com)
(Tyson Andre)

- Session:
. Fixed bug #74514 (5 session functions incorrectly warn when calling in
Expand Down
19 changes: 19 additions & 0 deletions ext/spl/php_spl.c
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,20 @@ PHP_FUNCTION(spl_object_hash)
}
/* }}} */

/* {{{ proto int spl_object_id(object obj)
Return integer hash id for 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;
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
24 changes: 24 additions & 0 deletions ext/spl/tests/spl_object_id.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
SPL: spl_object_id()
--FILE--
<?php

var_dump(spl_object_id(new stdClass));
var_dump(spl_object_id(42));
var_dump(spl_object_id());
$a = new stdClass();
var_dump(spl_object_id(new stdClass) === spl_object_id($a));

?>
===DONE===
<?php exit(0); ?>
--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===