Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79276 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 43275 invoked from network); 28 Nov 2014 13:52:01 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Nov 2014 13:52:01 -0000 Authentication-Results: pb1.pair.com smtp.mail=tyra3l@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=tyra3l@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.218.44 as permitted sender) X-PHP-List-Original-Sender: tyra3l@gmail.com X-Host-Fingerprint: 209.85.218.44 mail-oi0-f44.google.com Received: from [209.85.218.44] ([209.85.218.44:36129] helo=mail-oi0-f44.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AE/4D-59154-EFD78745 for ; Fri, 28 Nov 2014 08:51:58 -0500 Received: by mail-oi0-f44.google.com with SMTP id e131so4747525oig.31 for ; Fri, 28 Nov 2014 05:51:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=dPwOO4FIM9ANLc7efI5R18DAPOO+ciE5DlxM30lcUho=; b=lUNawPjk+PZW366V7yO7bUfA07G4f5MgCge/IexIIM7jOd61OvR1WhKg3AI2UV9fZT anVu5+c481K4hMVMRgzVQvj6xPeX3RngGpodkZDOi2d08mYxhijIxLXO3nz0ad7vUORY pzxm2mCd1Rs7Bj8VDzagDClTPjD/vxfFrh3Ytxyx3tgL+bGwLh/bYFPQriejGnsOxT33 UIUeLp9WCUdm32fqdods2L3reQw3fqQC36VCLD8zS7J/+QzUJ+kwuW7OFX8Mu44gEMHn Bq6ny5YlrIPaDKCidIuqUvzbcJxMbxw/JUOO8bxDSae2cQ/gnDtEkSVdCAfvOSGqqczh AXIQ== MIME-Version: 1.0 X-Received: by 10.60.115.227 with SMTP id jr3mr27292754oeb.33.1417182715486; Fri, 28 Nov 2014 05:51:55 -0800 (PST) Received: by 10.60.37.103 with HTTP; Fri, 28 Nov 2014 05:51:55 -0800 (PST) In-Reply-To: References: Date: Fri, 28 Nov 2014 14:51:55 +0100 Message-ID: To: Sebastian Krebs Cc: Bostjan Skufca , PHP Internals List Content-Type: multipart/alternative; boundary=089e0118424256a93f0508eb90b1 Subject: Re: [PHP-DEV] New function: spl_object_id() or spl_object_handle() From: tyra3l@gmail.com (Ferenc Kovacs) --089e0118424256a93f0508eb90b1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Fri, Nov 28, 2014 at 2:14 PM, Sebastian Krebs wrote: > 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: > > =3D=3D=3D=3D=3D=3D=3D=3D > > 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 wh= en > 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(), > yeah, the more I think about it the more I feel that the current implementation is just a landmine. you shouldn't store the return value and compare it later, even inside of the same request, because you could have collision if the object which the hash belongs gets freed before you compare. so basically the only safe usage would be the one where you have the two objects which you want to compare right away, but in that case, you could also just =3D=3D=3D them. I also used spl_object_hash() in the past when traversing/custom serializing object structures which can have infinite recursions between objects, but even that could be simply solved by storing the already traversed objects in an array (as assigning the objects into another variable doesn't have much overhead) and checking with in_array. would be nice hearing from others for what else are they using spl_object_hash() for. --=20 Ferenc Kov=C3=A1cs @Tyr43l - http://tyrael.hu --089e0118424256a93f0508eb90b1--