On Fri, 2014-11-28 at 02:13 +0100, Bostjan Skufca wrote: > Hello everyone, > > this is a proposal to add new function to PHP core: spl_object_id() > > > The story: > ======== > Recently I was debugging some larger libraries and sorely missed a function > that would return an object ID. A function called spl_object_hash() exists, > but it returns identical hashes for equal objects. You need object ID to be > really sure if two references are indeed the same object or two identical > objects. > > Most of the meat is described in this StackOverflow thread: > http://stackoverflow.com/questions/2872366/get-instance-id-of-an-object-in-php > > The OP proposes OB+var_dump() magic, which works if objects are small. > Unfortunatelly I was hitting "Allowed memory exceeded". > > The second answer, given by Gustavo Lopes, describes how to create an > extension for this, which provides new function, named spl_object_id(). I > believe this function should be included in PHP core. > > > > Sample implementation (not tested): > ============================= > /* {{{ proto string spl_object_id(object obj) > Return id for given object */ > PHP_FUNCTION(spl_object_id) > { > zval *obj; > > if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &obj) == FAILURE) > { > return; > } > RETURN_LONG(Z_OBJ_HANDLE_P(obj)); > } > /* }}} */ > > > > Two questions: > ============ > 1. Do you think this function should be included in PHP core? > 2. If so, what should this function be called? I am undecided between > spl_object_id() and spl_object_handle() and corresponding get_...() > variants. > > Ad 2. I lean towards ..._id() as ..._handle() suggests that you can do > something with that handle (think "open file handle", etc). > > > What is your opinion about this? > > Tnx, > b.
Morning, I don't think so, there is talk of removing object handles in 7. Even if we intended to keep object handles, this leaks implementation details that we don't really want leaked. Cheers Joe -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php