> Do you think there's an easy and clean approaching to solve this kind
> of problem? Or maybe the problem should be solved on array_diff() and
> other functions to make them not try to cast the object as a string to
> compare?
If use array_udiff with a comparison function that compares the
spl_ob
Hello Bruno,
the documentation says array_diff() uses explicit string casting. Maybe it
is time to fix this to object comparision. But then what about mixed arrays?
In my opinion it was broken before and you just got lucky with using a debug
feature without even knowing. Now the current PHP vers
On 7/30/07, Marcus Boerger <[EMAIL PROTECTED]> wrote:
> Hello Pavel,
>
> I still fail to understand why spl_object_hash() does not work for you.
Hello.
Just as a side note, this broke a few things for me. For example, in
an application, I have 2 arrays of objects, and I try to call
array_diff()
Hello Pavel,
I still fail to understand why spl_object_hash() does not work for you.
How about:
function foo($obj) {
if (is_object($obj)) {
return "object(" . get_class($obj) . ")#" . spl_object_hash($obj);
}
return NULL;
}
marcus
Sunday, July 1, 2007, 9:18:19 PM, you wrote:
>> Aga
Hello all,
and thanks Stas for the explanations.
Monday, July 2, 2007, 7:52:03 PM, you wrote:
>> We could add a counter that gets incremented for each object that is
>> created and associate that number with the object. Wouldn't that solve
>> the problem (if there is one)?
> It would solve
Hi Pavel,
Pavel Shevaev wrote:
Folks, is this really wanted behavior? Because if so, why does the
following result in the same hash as well(PHP-5.2.1)?
$ php -r "class Foo{};$foo = new
Foo();var_dump(spl_object_hash($foo));$foo->bar =
1;var_dump(spl_object_hash($foo));"
string(32) "d1f40a1cc04
On Sun, July 1, 2007 2:50 pm, Sebastian Bergmann wrote:
> Pavel Shevaev schrieb:
>> What I actually need, not the object hash but simply its unique id.
>
> The problem is that there is no such unique id in the current engine.
How does PHP internally distinguish it?
Surely it has some kind of poi
On Sun, July 1, 2007 2:18 pm, Pavel Shevaev wrote:
> $ php -r "class Foo{};$foo = new Foo();var_dump($foo);"
> object(Foo)#1 (0) {
> }
>
> What I actually need, not the object hash but simply its unique id.
According to Marcus, it's NOT unique.
But I can see that for debugging, it would be very v
The first is cleared before the second is instantiated.
Oh, that clears everything, please ignore my previous post. Still,
don't you think this is a bit misleading? IMHO, new object should
always have the unique id(or hash in terms of spl)...
That's a valid point, reusing IDs might be not a go
Not quite. It creates a hash of an object, so two objects with the same
data yield the same hashes:
var_dump(spl_object_hash(new stdClass()), spl_object_hash(new stdClass()));
here's the code of spl_object_hash:
len = spprintf(&hash, 0, "%p:%d", Z_OBJ_HT_P(obj), Z_OBJ_HANDLE_P(obj));
Oh, that clears everything, please ignore my previous post. Still,
don't you think this is a bit misleading? IMHO, new object should
always have the unique id(or hash in terms of spl)...
I don't like it either;) But it does exactly what Stanislav Malyshev
described: it hashes the "tuple of C po
The first is cleared before the second is instantiated.
Oh, that clears everything, please ignore my previous post. Still,
don't you think this is a bit misleading? IMHO, new object should
always have the unique id(or hash in terms of spl)...
--
Best regards, Pavel
--
PHP Internals - PHP Runti
Not quite. It creates a hash of an object, so two objects with the
same data yield the same hashes:
var_dump(spl_object_hash(new stdClass()), spl_object_hash(new stdClass
()));
Folks, is this really wanted behavior? Because if so, why does the
following result in the same hash as well(PHP-5.2.1
Not quite. It creates a hash of an object, so two objects with the
same data yield the same hashes:
var_dump(spl_object_hash(new stdClass()), spl_object_hash(new
stdClass()));
I don't believe that it's data dependent. Rather in your example the
same memory-space is used for those two objects
Am 01.07.2007 um 21:18 schrieb Pavel Shevaev:
Again see mail archive for why. That said the name appears to be
the best option already.
Oh, yes, you're right spl_object_hash does its job and does it very
well, there's really no point rename it(or make an alias) into
object_get_id. I should hav
On 02.07.2007 22:16, David wrote:
(Many apologies for the double e-mail. Ugh, I'm not used to hitting Reply To
All yet)
> I really don't want to be annoying but from the end user's POV
> spl_object_hash sounds like a function which returns a hash but not
an
> identity. Any tiny chance it will
Hmm. I think what Pavel is asking is just to make it clearer in the
documentation what spl_object_hash's purpose and workings are, and perhaps
make an alias to it named object_get_id so other people don't run into this
confusion in the future.
The name of spl_object_hash and the fact it is in the
(Many apologies for the double e-mail. Ugh, I'm not used to hitting Reply To
All yet)
> > I really don't want to be annoying but from the end user's POV
> > spl_object_hash sounds like a function which returns a hash but not
> an
> > identity. Any tiny chance it will be available as object_get_id
We could add a counter that gets incremented for each object that is
created and associate that number with the object. Wouldn't that solve
the problem (if there is one)?
It would solve it, but it would require modifying each extension dealing
with objects in order to register all objects in
Stanislav Malyshev schrieb:
> It does give the hash, which is unique for each object. In which form
> would you expect object_get_id to return object's identity? PHP doesn't
> have a type of "tuple of C pointer and long integer" ;)
We could add a counter that gets incremented for each object that
I really don't want to be annoying but from the end user's POV
spl_object_hash sounds like a function which returns a hash but not an
identity. Any tiny chance it will be available as object_get_id in
PHP6? ;)
It does give the hash, which is unique for each object. In which form
would you expec
Guys thank you all very much for this detailed explanation!
spl_object_hash is unique in the
terms of object identity.
I really don't want to be annoying but from the end user's POV
spl_object_hash sounds like a function which returns a hash but not an
identity. Any tiny chance it will be ava
will be generated. It looks like it's independent of the actual properties,
etc. of the object. Spl_object_hash is what you guys want.
Sure, object identity is not related to properties in any way. Same
object can have different properties during the lifetime, and different
objects can have id
Am I right in my guess that there's only a counter for each object
type? Still being not really unique this information could be very
useful and enough in many situations.
It's more complicated than that. Basically what uniquely identifies the
object is the tuple (handlers, ID) - it's more or l
(accidentally didn't send this to the whole group at first)
> Am I right in my guess that there's only a counter for each object
> type? Still being not really unique this information could be very
> useful and enough in many situations.
The "counter" is global, but it's not really a counter. "
The problem is that there is no such unique id in the current engine.
Am I right in my guess that there's only a counter for each object
type? Still being not really unique this information could be very
useful and enough in many situations.
--
Best regards, Pavel
--
PHP Internals - PHP Runti
The problem is that there is no such unique id in the current engine.
Okay!;) That's a very good reason, I guess;) Explains a lot. Why not use
spl_object_hash instead of the old default behaviour?
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.ph
Pavel Shevaev schrieb:
> What I actually need, not the object hash but simply its unique id.
The problem is that there is no such unique id in the current engine.
--
Sebastian Bergmann http://sebastian-bergmann.de/
GnuPG Key: 0xB85B5D69 / 27A7 2B14 09E4 98CD 6277 0E5B 6
What I actually need, not the object hash but simply its unique id.
And in this case "object(Foo)#1" would be just fine. How can I get it?
That was my original Question too;) It's been stated that the automatic
cast into a string even if it does not implement the __toString()
function was "abs
Again see mail archive for why. That said the name appears to be
the best option already.
Oh, yes, you're right spl_object_hash does its job and does it very
well, there's really no point rename it(or make an alias) into
object_get_id. I should have stated more clear what I think
object_get_id c
Hello Pavel,
technically object id is neither what you get nor what you want. It is not
unique and thus not helpfull and we have no intention to ever provide a
function to access it. See mail archieve for reference on why we won't.
Also the function resides in extension SPL so correctly it is pr
SPL is "in the core" AFAIAC.
I really want to hope it will be in PHP6. Still IMHO get_object_id
sounds much better than spl_object_hash and it will be much easier(and
more logical) to locate this function in "Class/Object Functions"
section of documentation than in SPL...
--
Best regards, Pav
Hello Gwynne,
no more unnecessary aliases please.
marcus
Sunday, July 1, 2007, 9:27:25 AM, you wrote:
> On Jul 1, 2007, at 3:24 AM, Pavel Shevaev wrote:
>>> > always helpful). Is there any other way than casting an object to a
>>> > string to get an objects #ID?
>>>
>>> spl_object_hash?
>> Gu
Pavel Shevaev schrieb:
> Guys, excuse my being a little offtopic here, but why not introduce
> standard "get_object_id" function in PHP6 which could be analogous to
> "spl_object_hash"? IMHO it's a basic functionality which deserves to
> be in the core...
SPL is "in the core" AFAIAC.
--
Sebasti
On Jul 1, 2007, at 3:24 AM, Pavel Shevaev wrote:
> always helpful). Is there any other way than casting an object to a
> string to get an objects #ID?
spl_object_hash?
Guys, excuse my being a little offtopic here, but why not introduce
standard "get_object_id" function in PHP6 which could be an
On 6/30/07, Stanislav Malyshev <[EMAIL PROTECTED]> wrote:
> always helpful). Is there any other way than casting an object to a
> string to get an objects #ID?
spl_object_hash?
Guys, excuse my being a little offtopic here, but why not introduce
standard "get_object_id" function in PHP6 which c
On 6/29/07, Lars Schultz <[EMAIL PROTECTED]> wrote:
Hi there
I just tried to switch from 5.1 to 5.2.3 and got thrown off right away by:
"Object of class MyObject could not be converted to string"
I googled a bit and also read any Messages in the internals list but
couldn't find a decisive answe
always helpful). Is there any other way than casting an object to a
string to get an objects #ID?
spl_object_hash?
--
Stanislav Malyshev, Zend Software Architect
[EMAIL PROTECTED] http://www.zend.com/
(408)253-8829 MSN: [EMAIL PROTECTED]
--
PHP Internals - PHP Runtime Development Mailing Li
Hi Lars,
In the meanwhile .. check out spl_object_hash
Evert
Lars Schultz wrote:
Hi there
I just tried to switch from 5.1 to 5.2.3 and got thrown off right away
by:
"Object of class MyObject could not be converted to string"
I googled a bit and also read any Messages in the internals list
Hi there
I just tried to switch from 5.1 to 5.2.3 and got thrown off right away by:
"Object of class MyObject could not be converted to string"
I googled a bit and also read any Messages in the internals list but
couldn't find a decisive answer as to wether this will stay this way or not.
I
40 matches
Mail list logo