I want to create wrapper class, which will enable keys duplicates while default hash does not allow it. Class should use member overloading mechanism introduced in php5, so it would imitate all the behavior standard hash has. For example, I want to have smth like
$var => obj( :values_arr -> array(
obj(:key -> 'mykey', :value -> 'val1'),
obj(:key -> 'mykey', :value -> 'val2')
)
)
If I want to get $var['mykey'], it should return array('val1', 'val2'), but if I want to extend obj with new 'mykey' => 'value' pair, I would call
$val['mykey'][] = 'value'
Main idea is that behavior of the hash was preserved and after attempt to assign value to using existing key, it wouldn't be overwritten, but appended to the list.
How would you imitate other data structures in php5 (before 5.3)? Are there any known solutions or examples you want to share?