|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-04-29 17:49 UTC] colder@php.net
-Status: Open
+Status: Closed
-Assigned To:
+Assigned To: colder
[2010-04-29 17:49 UTC] colder@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 16 23:00:01 2025 UTC |
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 ];