|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-08-03 23:05 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 17:00:01 2025 UTC |
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