Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79255 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 78170 invoked from network); 28 Nov 2014 01:14:02 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Nov 2014 01:14:02 -0000 Authentication-Results: pb1.pair.com header.from=bostjan@a2o.si; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=bostjan@a2o.si; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain a2o.si designates 78.47.12.76 as permitted sender) X-PHP-List-Original-Sender: bostjan@a2o.si X-Host-Fingerprint: 78.47.12.76 portkey.s.itsis.si Received: from [78.47.12.76] ([78.47.12.76:39450] helo=portkey.s.itsis.si) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5B/53-59154-85CC7745 for ; Thu, 27 Nov 2014 20:14:01 -0500 Received: from undisclosed (undisclosed [127.0.0.254]) (Authenticated sender: undisclosed) by portkey.s.itsis.si (Postfix) with ESMTPSA id 1247B8006B for ; Fri, 28 Nov 2014 01:13:57 +0000 (UTC) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.98.4 at portkey Received: by mail-ig0-f177.google.com with SMTP id z20so4986899igj.10 for ; Thu, 27 Nov 2014 17:13:55 -0800 (PST) MIME-Version: 1.0 X-Received: by 10.50.142.98 with SMTP id rv2mr27920042igb.19.1417137235406; Thu, 27 Nov 2014 17:13:55 -0800 (PST) Received: by 10.50.35.1 with HTTP; Thu, 27 Nov 2014 17:13:55 -0800 (PST) Date: Fri, 28 Nov 2014 02:13:55 +0100 Message-ID: To: PHP Internals List Content-Type: multipart/alternative; boundary=001a1136b7d883b72f0508e0f9a5 Subject: New function: spl_object_id() or spl_object_handle() From: bostjan@a2o.si (Bostjan Skufca) --001a1136b7d883b72f0508e0f9a5 Content-Type: text/plain; charset=UTF-8 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. --001a1136b7d883b72f0508e0f9a5--