Req #52528 [Opn->Wfx]: request for interface hashCode (Identifiable)

From: Date: Sat, 14 Mar 2015 15:40:37 +0000
Subject: Req #52528 [Opn->Wfx]: request for interface hashCode (Identifiable)
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-191383@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=52528&edit=1

 ID:                 52528
 Updated by:         nikic@php.net
 Reported by:        giorgio dot liscio at email dot it
 Summary:            request for interface hashCode (Identifiable)
-Status:             Open
+Status:             Wont fix
 Type:               Feature/Change Request
 Package:            Class/Object related
 Operating System:   irr
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

RFC for this https://wiki.php.net/rfc/objkey has been
declined, so closing this as Won't Fix.


Previous Comments:
------------------------------------------------------------------------
[2010-10-03 18:51:49] + at ni-po dot com

I see no reason for this to be implemented. Generate an spl_object_hash, use (string) casting or
implement your own ->toHash() method.

This is something you will want to do only ***very*** rarely. Thus it shouldn't pollute the
interface namespace.

------------------------------------------------------------------------
[2010-08-03 23:20:42] jackohman at eugama dot com

would be really nice having the possibility to use different output strings, one for readability,
one for unique identify an object

class ArrayObject implements Identifiable
{
      function hashCode(){return spl_object_hash($this);}
      function __toString(){return json_encode($this);}
}

$obj = new ArrayObject();
$myarr[$obj] = (String)$obj;

very nice, i'm voting it

------------------------------------------------------------------------
[2010-08-03 23:05:24] giorgio dot liscio at email dot it

Description:
------------
i, i hope to see something like this in future php releases


interface Identifiable
{
     public function /*string*/ hashCode();
}


class Test implements Identifiable
{
     public function hashCode(){return spl_object_hash($this);}
}


method hashCode() should be called in these contexts:


$myarr[new Test()] = "test";
$myarrobj->{new Test()} = "test";
and manually inside:
function method(Identifiable $instance){};


the hash should be obtained by calling

$obj->hashCode()     if it is Identifiable or
$obj->scalarValue()  if it implements ScalarAccess
$obj->__toString()   if it has method __toString

or, finally throw an error

what do you think about this?
thank you




------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=52528&edit=1


Thread (4 messages)

« previous php.bugs (#191383) next »