[PHP-DEV] [RFC] Using objects as keys

2014-10-26 Thread Stas Malyshev
Hi! I would like to present to your attention an RFC about using object as keys: https://wiki.php.net/rfc/objkey It was discussed in the past on the list: http://marc.info/?t=14114596961&r=1&w=2 and I think it makes sense to propose a formal RFC for it. Both the text and the code in the patc

Re: [PHP-DEV] [RFC] Using objects as keys

2014-10-26 Thread Will Fitch
> On Oct 26, 2014, at 8:37 PM, Stas Malyshev wrote: > > Hi! > > I would like to present to your attention an RFC about using object as keys: > > https://wiki.php.net/rfc/objkey > Hi Stas! I’m trying to wrap my head around a real-world use-case with this. We have spl_object_hash, which eff

Re: [PHP-DEV] [RFC] Using objects as keys

2014-10-26 Thread Stas Malyshev
Hi! > I’m trying to wrap my head around a real-world use-case with this. > We have spl_object_hash, which effectively provides a unique hash for This hash has nothing to do with object's contents. But imagine number GMP("42") and imagine you actually want two GMP objects expressing "42" actually

Re: [PHP-DEV] [RFC] Using objects as keys

2014-10-26 Thread Will Fitch
> On Oct 26, 2014, at 9:43 PM, Stas Malyshev wrote: > > Hi! > >> I’m trying to wrap my head around a real-world use-case with this. >> We have spl_object_hash, which effectively provides a unique hash for > > This hash has nothing to do with object's contents. But imagine number > GMP("42") an

Re: [PHP-DEV] [RFC] Using objects as keys

2014-10-26 Thread Joe Watkins
On Sun, 2014-10-26 at 18:37 -0700, Stas Malyshev wrote: > Hi! > > I would like to present to your attention an RFC about using object as keys: > > https://wiki.php.net/rfc/objkey > > It was discussed in the past on the list: > http://marc.info/?t=14114596961&r=1&w=2 > and I think it makes se

Re: [PHP-DEV] [RFC] Using objects as keys

2014-10-26 Thread Stas Malyshev
Hi! > It seems __toScalar might be a good name, this is what the method > actually does, the engine then coerces to a type suitable for use as a > key, but you can return a double. It might be more forward thinking > therefore to use the name __toScalar, while today we'd only be using > it for thi

Re: [PHP-DEV] [RFC] Using objects as keys

2014-10-26 Thread Will Fitch
> On Oct 27, 2014, at 1:36 AM, Stas Malyshev wrote: > > Hi! > >> It seems __toScalar might be a good name, this is what the method >> actually does, the engine then coerces to a type suitable for use as a >> key, but you can return a double. It might be more forward thinking >> therefore to use

Re: [PHP-DEV] [RFC] Using objects as keys

2014-10-26 Thread Patrick Schaaf
Am 27.10.2014 02:37 schrieb "Stas Malyshev" : > > I would like to present to your attention an RFC about using object as keys: > >https://wiki.php.net/rfc/objkey I don't like this, mainly because it blocks a future direct use and storage of objects as keys in an array, i.e. what SplObjectStorage d

Re: [PHP-DEV] [RFC] Using objects as keys

2014-10-27 Thread Joe Watkins
On Sun, 2014-10-26 at 23:36 -0700, Stas Malyshev wrote: > Hi! > > > It seems __toScalar might be a good name, this is what the method > > actually does, the engine then coerces to a type suitable for use as a > > key, but you can return a double. It might be more forward thinking > > therefore to

Re: [PHP-DEV] [RFC] Using objects as keys

2014-10-27 Thread Stas Malyshev
Hi! > I don't like this, mainly because it blocks a future direct use and storage > of objects as keys in an array, i.e. what SplObjectStorage does. It does not. It just allows the objects to control how they are seen when they are used as keys in regular PHP arrays. That does not prevent SplObje

Re: [PHP-DEV] [RFC] Using objects as keys

2014-10-27 Thread Patrick Schaaf
Am 27.10.2014 08:09 schrieb "Stas Malyshev" : > > > I don't like this, mainly because it blocks a future direct use and storage > > of objects as keys in an array, i.e. what SplObjectStorage does. > > It does not. It just allows the objects to control how they are seen > when they are used as keys

Re: [PHP-DEV] [RFC] Using objects as keys

2014-10-27 Thread Stas Malyshev
Hi! > Once your proposal is in the language, you will never, in the future, be > able to add real support for objects as keys, because the semantics is > blocked. This implies this support is not "real" and we want some other support. I don't think I agree with either. > I do understand where yo

Re: [PHP-DEV] [RFC] Using objects as keys

2014-10-27 Thread Joe Watkins
On Mon, 2014-10-27 at 00:41 -0700, Stas Malyshev wrote: > Hi! > > > Once your proposal is in the language, you will never, in the future, be > > able to add real support for objects as keys, because the semantics is > > blocked. > > This implies this support is not "real" and we want some other s

Re: [PHP-DEV] [RFC] Using objects as keys

2014-10-27 Thread Michael Wallner
On 27/10/14 08:09, Stas Malyshev wrote: > Hi! > >> I don't like this, mainly because it blocks a future direct use and storage >> of objects as keys in an array, i.e. what SplObjectStorage does. > > It does not. It just allows the objects to control how they are seen > when they are used as keys

Re: [PHP-DEV] [RFC] Using objects as keys

2014-10-27 Thread Michael Wallner
On 27/10/14 04:08, Will Fitch wrote: > >> On Oct 26, 2014, at 9:43 PM, Stas Malyshev >> wrote: >> >> Hi! >> >>> I’m trying to wrap my head around a real-world use-case with >>> this. We have spl_object_hash, which effectively provides a >>> unique hash for >> >> This hash has nothing to do wit

Re: [PHP-DEV] [RFC] Using objects as keys

2014-10-27 Thread Lester Caine
On 27/10/14 01:37, Stas Malyshev wrote: > The name __hash is not final, I am open to using __toKey instead or any > reasonable alternative, we may also include a couple of options in the > vote if that will be a point of disagreement. I don't think it's clear from the RFC ... Is the resulting valu

Re: [PHP-DEV] [RFC] Using objects as keys

2014-10-27 Thread Andrea Faulds
> On 27 Oct 2014, at 06:36, Stas Malyshev wrote: > > Hi! > >> It seems __toScalar might be a good name, this is what the method >> actually does, the engine then coerces to a type suitable for use as a >> key, but you can return a double. It might be more forward thinking >> therefore to use th

Re: [PHP-DEV] [RFC] Using objects as keys

2014-10-27 Thread Alexander Lisachenko
Hello, internals! > The name __hash is not final, I am open to using __toKey instead or any > reasonable alternative, we may also include a couple of options in the > vote if that will be a point of disagreement. I like this idea with custom hash implementation because spl_object_hash() is not re

Re: [PHP-DEV] [RFC] Using objects as keys

2014-10-27 Thread Levi Morrison
> I would like to present to your attention an RFC about using object as keys: > > https://wiki.php.net/rfc/objkey A few points I have against this proposal, as I understand it: - It does not store the object, only the result of `__hash`. Without the actual object this is not helpful for any u

Re: [PHP-DEV] [RFC] Using objects as keys

2014-10-27 Thread Lazare Inepologlou
2014-10-27 16:54 GMT+01:00 Levi Morrison : > > I would like to present to your attention an RFC about using object as > keys: > > > > https://wiki.php.net/rfc/objkey > > A few points I have against this proposal, as I understand it: > > - It does not store the object, only the result of `__hash

Re: [PHP-DEV] [RFC] Using objects as keys

2014-10-27 Thread Johannes Schlüter
On Mon, 2014-10-27 at 09:35 +0100, Michael Wallner wrote: > Actually, I see spl_object_hash($this) the 90% implementation of > __hash(), so how about making it the default for any object? I agree - it might be a good default. To Will's question: It is not sufficient for all cases. Having a custom

Re: [PHP-DEV] [RFC] Using objects as keys

2014-10-27 Thread Stas Malyshev
Hi! > Is the resulting value intended always to return the same object > independent of what has been done to the object in the mean time? That's on you to decide. If you have immutable value object, then yes. If you have mutable value object (which usually isn't a good idea, but who knows) then n

Re: [PHP-DEV] [RFC] Using objects as keys

2014-10-27 Thread Etienne Kneuss
On Mon, Oct 27, 2014 at 2:37 AM, Stas Malyshev wrote: > Hi! > > I would like to present to your attention an RFC about using object as > keys: > > https://wiki.php.net/rfc/objkey > > I think it should be made clear that what the target of your RFC is not to support objects as keys, what you prop

Re: [PHP-DEV] [RFC] Using objects as keys

2014-10-27 Thread Stas Malyshev
Hi! > As others noted, it also prevents a full-fledged objects-as-key > implementation in the future. You do realize to have such implementation we'd need to rewrite our hash layer completely and also introduce the concept of immutable object, otherwise changing the object would make the hash compl

Re: [PHP-DEV] [RFC] Using objects as keys

2014-10-27 Thread Rowan Collins
On 27 October 2014 18:11:48 GMT, Stas Malyshev wrote: >Hi! >> As others noted, it also prevents a full-fledged objects-as-key >> implementation in the future. >You do realize to have such implementation we'd need to rewrite our >hash >layer completely and also introduce the concept of immutable ob

Re: [PHP-DEV] [RFC] Using objects as keys

2014-10-28 Thread Etienne Kneuss
On Mon, Oct 27, 2014 at 7:11 PM, Stas Malyshev wrote: > Hi! > > As others noted, it also prevents a full-fledged objects-as-key > > implementation in the future. > You do realize to have such implementation we'd need to rewrite our hash > layer completely and also introduce the concept of immutab

Re: [PHP-DEV] [RFC] Using objects as keys

2014-10-28 Thread Matteo Beccati
Hi Stas, On 27/10/2014 18:39, Etienne Kneuss wrote: > I think it should be made clear that what the target of your RFC is not to > support objects as keys, what you propose instead is an implicit > translation from: > > $a[$obj] > to > $a[$obj->__hash()] > > This is clearly different. I agree t

RE: [PHP-DEV] [RFC] Using objects as keys

2014-10-30 Thread Christian Stoller
From: Alexander Lisachenko [mailto:lisachenko...@gmail.com], Sent: Monday, October 27, 2014 11:18 AM > Hello, internals! > >> The name __hash is not final, I am open to using __toKey instead or any >> reasonable alternative, we may also include a couple of options in the >> vote if that will be

Re: [PHP-DEV] [RFC] Using objects as keys

2014-10-30 Thread Will Fitch
> On Oct 30, 2014, at 2:13 AM, Christian Stoller wrote: > > > From: Alexander Lisachenko [mailto:lisachenko...@gmail.com], Sent: Monday, > October 27, 2014 11:18 AM > >> Hello, internals! >> >>> The name __hash is not final, I am open to using __toKey instead or any >>> reasonable alternativ

Re: [PHP-DEV] [RFC] Using objects as keys

2014-10-30 Thread Lester Caine
On 30/10/14 07:19, Will Fitch wrote: > The magic method is more of a PHP approach while an interface would be more > appropriate. That said, this RFC is a true representation of a hash vs > something like spl_object_hash. That’s what causes user confusion. > spl_object_hash would’ve been bett

Re: [PHP-DEV] [RFC] Using objects as keys

2014-10-30 Thread Rowan Collins
On 30 October 2014 10:40:10 GMT, Lester Caine wrote: >On 30/10/14 07:19, Will Fitch wrote: >> The magic method is more of a PHP approach while an interface would >be more appropriate. That said, this RFC is a true representation of a >hash vs something like spl_object_hash. That’s what causes us

Re: [PHP-DEV] [RFC] Using objects as keys

2014-10-30 Thread Lester Caine
On 30/10/14 15:06, Rowan Collins wrote: > On 30 October 2014 10:40:10 GMT, Lester Caine wrote: >> On 30/10/14 07:19, Will Fitch wrote: >>> The magic method is more of a PHP approach while an interface would >> be more appropriate. That said, this RFC is a true representation of a >> hash vs somet

Re: [PHP-DEV] [RFC] Using objects as keys

2014-10-30 Thread Rowan Collins
Lester Caine wrote on 30/10/2014 16:44: On 30/10/14 15:06, Rowan Collins wrote: On 30 October 2014 10:40:10 GMT, Lester Caine wrote: On 30/10/14 07:19, Will Fitch wrote: The magic method is more of a PHP approach while an interface would be more appropriate. That said, this RFC is a true re

Re: [PHP-DEV] [RFC] Using objects as keys

2014-10-30 Thread Larry Garfield
On 10/30/14, 2:19 AM, Will Fitch wrote: On Oct 30, 2014, at 2:13 AM, Christian Stoller wrote: From: Alexander Lisachenko [mailto:lisachenko...@gmail.com], Sent: Monday, October 27, 2014 11:18 AM Hello, internals! The name __hash is not final, I am open to using __toKey instead or any

Re: [PHP-DEV] [RFC] Using objects as keys

2014-10-30 Thread Stas Malyshev
Hi! > Put another way, I think a key question here is: > > class Foo { >public $bar; > } > > $a = new Foo; > $a->bar = 'baz'; > $b = new Foo; > $b->bar = 'baz'; > > $arr[$a] = true; > $arr[$b] = true; > > > Does $arr now contain one value or two? That depends on the semantics of class Fo

Re: [PHP-DEV] [RFC] Using objects as keys

2014-10-30 Thread Rowan Collins
Larry Garfield wrote on 30/10/2014 18:07: On 10/30/14, 2:19 AM, Will Fitch wrote: On Oct 30, 2014, at 2:13 AM, Christian Stoller wrote: From: Alexander Lisachenko [mailto:lisachenko...@gmail.com], Sent: Monday, October 27, 2014 11:18 AM Hello, internals! The name __hash is not final

Re: [PHP-DEV] [RFC] Using objects as keys

2014-10-30 Thread Will Fitch
> On Oct 30, 2014, at 1:32 PM, Stas Malyshev wrote: > > Hi! > >> Put another way, I think a key question here is: >> >> class Foo { >> public $bar; >> } >> >> $a = new Foo; >> $a->bar = 'baz'; >> $b = new Foo; >> $b->bar = 'baz'; >> >> $arr[$a] = true; >> $arr[$b] = true; >> >> >> Does

Re: [PHP-DEV] [RFC] Using objects as keys

2014-10-30 Thread Stas Malyshev
Hi! > My only concern at this point is the default value of the hash. If we > were to use spl _object_hash, we could be setting a precedence that a > hash must be unique to each object. I don't think there should be any default value. Most objects are not suitable as keys, only some of them are (

Re: [PHP-DEV] [RFC] Using objects as keys

2014-10-30 Thread Andrea Faulds
> On 30 Oct 2014, at 19:51, Will Fitch wrote: > > My only concern at this point is the default value of the hash. If we were to > use spl _object_hash, we could be setting a precedence that a hash must be > unique to each object. In addition to what Stas says above, well, not all objects work

Re: [PHP-DEV] [RFC] Using objects as keys

2014-10-30 Thread Will Fitch
> On Oct 30, 2014, at 3:28 PM, Andrea Faulds wrote: > > >> On 30 Oct 2014, at 19:51, Will Fitch wrote: >> >> My only concern at this point is the default value of the hash. If we were >> to use spl _object_hash, we could be setting a precedence that a hash must >> be unique to each object.

Re: [PHP-DEV] [RFC] Using objects as keys

2014-10-30 Thread Lester Caine
On 30/10/14 17:42, Rowan Collins wrote: > The use case which came up recently was UString objects, which can > easily be converted to and from plain PHP strings, but would be useful > as keys in their own right. With current PHP you could do $foo[ > (string)$u_str ] = $bar; with the proposed RFC, y

Re: [PHP-DEV] [RFC] Using objects as keys

2014-10-30 Thread Will Fitch
> On Oct 30, 2014, at 6:20 PM, Lester Caine wrote: > > On 30/10/14 17:42, Rowan Collins wrote: >> The use case which came up recently was UString objects, which can >> easily be converted to and from plain PHP strings, but would be useful >> as keys in their own right. With current PHP you could