Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79256 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 83905 invoked from network); 28 Nov 2014 03:10:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Nov 2014 03:10:50 -0000 Authentication-Results: pb1.pair.com header.from=reeze.xia@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=reeze.xia@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.47 as permitted sender) X-PHP-List-Original-Sender: reeze.xia@gmail.com X-Host-Fingerprint: 74.125.82.47 mail-wg0-f47.google.com Received: from [74.125.82.47] ([74.125.82.47:57164] helo=mail-wg0-f47.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F6/E3-59154-8B7E7745 for ; Thu, 27 Nov 2014 22:10:49 -0500 Received: by mail-wg0-f47.google.com with SMTP id n12so7803792wgh.34 for ; Thu, 27 Nov 2014 19:10:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=ZHAkllQpncxSruAwbxiG0+ovQsPZyNgfqYlimovaosY=; b=Rps5lzIb/UNhaAab3OQuQ7FxGUtWE0rrY4mJZbWBNtbH9v4cZ8h0jc6OSTOrBCLEWd UXOCd2ryaIHCLUC46obF46S8s+dhHyEifYkZ3xI0278EI7p//SquzRqslsByUUf5waTM pVvB0KF2nGTpfCgQctYVF2tzD2v6BLxKw3RsVzaD9QQTXn8u820t6ACMQ9/YjcS5uK50 dQOH2OzVnrywIKuyHIV5T6fGawAom+MWdAZsdgUx+dyqgO7o1R0iW2L/E9CLvtr6zGwN zG1O0j95MQl8wxaasLcX+GTqgcM1hNDoHf6RTKwyGqzbAHeOCJom7awAALogemjCX76c 42kg== X-Received: by 10.180.78.225 with SMTP id e1mr35947745wix.32.1417144245376; Thu, 27 Nov 2014 19:10:45 -0800 (PST) MIME-Version: 1.0 Sender: reeze.xia@gmail.com Received: by 10.194.175.227 with HTTP; Thu, 27 Nov 2014 19:10:25 -0800 (PST) In-Reply-To: References: Date: Fri, 28 Nov 2014 11:10:25 +0800 X-Google-Sender-Auth: dh5c8LgPdCEapCR5MLlwGHsKMKA Message-ID: To: Bostjan Skufca Cc: PHP Internals List Content-Type: multipart/alternative; boundary=f46d043c0864575f2d0508e29bbc Subject: Re: [PHP-DEV] New function: spl_object_id() or spl_object_handle() From: reeze@php.net (reeze) --f46d043c0864575f2d0508e29bbc Content-Type: text/plain; charset=ISO-8859-1 Won't `$obj1 === $obj2` work for you ? On 28 November 2014 at 09:13, 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. > --f46d043c0864575f2d0508e29bbc--