Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79275 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 40272 invoked from network); 28 Nov 2014 13:15:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Nov 2014 13:15:07 -0000 Authentication-Results: pb1.pair.com header.from=krebs.seb@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=krebs.seb@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.173 as permitted sender) X-PHP-List-Original-Sender: krebs.seb@gmail.com X-Host-Fingerprint: 209.85.212.173 mail-wi0-f173.google.com Received: from [209.85.212.173] ([209.85.212.173:58285] helo=mail-wi0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7C/DC-59154-A5578745 for ; Fri, 28 Nov 2014 08:15:06 -0500 Received: by mail-wi0-f173.google.com with SMTP id r20so18531134wiv.6 for ; Fri, 28 Nov 2014 05:15:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=cSm2knzzrXCOOcSnuASDkdGoe+SfajkVdXRp+u0k7U8=; b=wG9EFgkAhIwvVqLrnbdnlm/rv9IM6SL6Z74bk56pB0AsY6U8ogr4qOo0qr8URUO2vF 1yq5m5vRPA4CPiAWrQ7DHuyUURs8HmXhOAlEoaxVfPO5Zmm1UEPDVdDksFsM1afFMLCo 5BOv0Jt8ShtQm7zHmdYt+9p3Lj/6xmFq4uiYqSS1lXh+xhoB1hvstAh/szWBmWAhkY5K V/Q57i1D7K4IeQWJHPyBh7QGkmdzkxj8Jdrbj4IpZJK/tSLwxiygiPhcxr90gLKB/K8a Se71UQwyTiBBmOd0uGlu9yZ0phZSO/txj1wSIoNWJ8qo3VhhtpZUZEjwv0NdArivQkHs guNw== X-Received: by 10.194.187.235 with SMTP id fv11mr39663601wjc.16.1417180502575; Fri, 28 Nov 2014 05:15:02 -0800 (PST) MIME-Version: 1.0 Received: by 10.216.20.131 with HTTP; Fri, 28 Nov 2014 05:14:22 -0800 (PST) In-Reply-To: References: Date: Fri, 28 Nov 2014 14:14:22 +0100 Message-ID: To: Bostjan Skufca Cc: PHP Internals List Content-Type: multipart/alternative; boundary=047d7bdcab847055120508eb0c16 Subject: Re: [PHP-DEV] New function: spl_object_id() or spl_object_handle() From: krebs.seb@gmail.com (Sebastian Krebs) --047d7bdcab847055120508eb0c16 Content-Type: text/plain; charset=UTF-8 2014-11-28 2:13 GMT+01:00 Bostjan Skufca : > 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. It returns unique IDs for existing objects. A hash is only reused only when the corresponding object was removed by the GC earlier. So actually asking me it makes more sense to "fix" the behaviour of spl_object_hash(), > 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. > -- github.com/KingCrunch --047d7bdcab847055120508eb0c16--