Req #51345 [Opn->Csd]: Ability to override the hash function used by SplObjectStorage

From: Date: Thu, 29 Apr 2010 15:49:09 +0000
Subject: Req #51345 [Opn->Csd]: Ability to override the hash function used by SplObjectStorage
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-150028@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=51345&edit=1

 ID:               51345
 Updated by:       colder@php.net
 Reported by:      tejas dot net at gmail dot com
 Summary:          Ability to override the hash function used by
                   SplObjectStorage
-Status:           Open
+Status:           Closed
 Type:             Feature/Change Request
 Package:          SPL related
 Operating System: CentOS v5
 PHP Version:      5.3.2
-Assigned To:      
+Assigned To:      colder

 New Comment:

This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

SplObjectStorage now implements a getHash($obj) method, so you can
extend 
SplObjectStorage and overwrite that method to suit your needs.


Previous Comments:
------------------------------------------------------------------------
[2010-03-21 19:55:35] tejas dot net at gmail dot com

Description:
------------
SplObjectStorage will be a lot more useful if I could override the hash
function 
it uses, so different objects which are really equal will be recognized
as such by 
SplObjectStorage.

While I currently do this by jumping through a few hoops, this will be a
welcome 
addition. A __hashCode() magic method can accomplish this easily.

Test script:
---------------
Pseudo-code:
<?
class StockSecurity {
	public $exchange;
	public $ticker;
	
	public function __hashCode() {
		return $this->exchange . ":" . $this->ticker;
	}
}

$d = new SplObjectStorage();
$s = new StockSecurity( 'NASDAQ', 'GOOG' );
$d->attach( $s, getStockQuote( $s ) );

// later on, in a different method
$s = new StockSecurity( 'NASDAQ', 'GOOG' );
$quote = $d[ $s ];



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



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


Thread (2 messages)

« previous php.bugs (#150028) next »