There was a proposal back in 2015 to implement
a function spl_object_id(object $o) : int, which directly returns the object handle (similar to
spl_object_hash`, but as an integer, not a string).
I'm interested in finishing implementing spl_object_id for php 7.2
I already have working code implementing spl_object_id() at
https://github.com/TysonAndre/php-src/pull/1
The implementation XORs the object handle with the
exact same random bits that spl_object_hash
would.
Previous emails from 2015 can be seen here:
Previous comment by a PHP maintainer in support of spl_object_id()
I'm unsure if an RFC is necessary. I have two pending questions.
- Can two objects can have the same object id
but different object handlers?
(e.g. iterators of some built in classes?)
I'm not familiar enough with PHP's history to be sure. - Can the the largest object handle be larger
than the size ofzend_long
in 32-bit systems?
Example places where this would be useful:
-
I also recently wanted to track a large number of (cloneable)
small sets of objects in an application that sometimes used a lot of memory,
and the fact that arrays support copy on write helped save memory
relative to SplObjectHash if arrays and integer keys were used.
See https://github.com/etsy/phan/pull/729#issuecomment-299289378
- Tyson Andre (tandre)
Hi!
- Can two objects can have the same object id
but different object handlers?
(e.g. iterators of some built in classes?)
I'm not familiar enough with PHP's history to be sure.
Yes, if extension using non-standard handlers is in use.
- Can the the largest object handle be larger
than the size ofzend_long
in 32-bit systems?
Handle is uint32_t, so probably no.
--
Stas Malyshev
smalyshev@gmail.com
Hi,
-----Original Message-----
From: Stanislav Malyshev [mailto:smalyshev@gmail.com]
Sent: Wednesday, July 5, 2017 5:28 AM
To: tyson andre tysonandre775@hotmail.com; internals@lists.php.net
Subject: Re: [PHP-DEV] Exposing object handles to userlandHi!
- Can two objects can have the same object id
but different object handlers?
(e.g. iterators of some built in classes?)
I'm not familiar enough with PHP's history to be sure.Yes, if extension using non-standard handlers is in use.
- Can the the largest object handle be larger
than the size ofzend_long
in 32-bit systems?Handle is uint32_t, so probably no.
On 32-bit zend_long is a signed 32-bit int, so it can theoretically overflow, while sizeof is same.
Regards
Anatol
Hi!
On 32-bit zend_long is a signed 32-bit int, so it can theoretically overflow, while sizeof is same.
Well, it's the same issue we having on representing any unsigned values,
I guess. Since int<->uint in this case is one-to-one, should be ok to
just use the negative nums, if they are used as IDs and not to calculate
anything, etc. So I don't think it's much of a problem here.
--
Stas Malyshev
smalyshev@gmail.com
On Wed, Jul 5, 2017 at 2:01 AM, tyson andre tysonandre775@hotmail.com
wrote:
There was a proposal back in 2015 to implement
a function spl_object_id(object $o) : int, which directly returns the object handle (similar to
spl_object_hash`, but as an integer, not a string).
I'm interested in finishing implementing spl_object_id for php 7.2I already have working code implementing spl_object_id() at
https://github.com/TysonAndre/php-src/pull/1
The implementation XORs the object handle with the
exact same random bits thatspl_object_hash
would.
You can drop the masking. It was never effective at what it's supposed to
do (hide memory addresses), but as this is the object ID only, it is
completely unnecessary here.
Previous emails from 2015 can be seen here:
Previous comment by a PHP maintainer in support of
spl_object_id()
I'm unsure if an RFC is necessary. I have two pending questions.
I'm +1 on the addition and would be fine with including it without RFC, if
there are no objections on internals.
- Can two objects can have the same object id
but different object handlers?
(e.g. iterators of some built in classes?)
I'm not familiar enough with PHP's history to be sure.
No: In PHP 7 this is not possible, which is also why spl_object_hash()
no
longer includes the handlers.
- Can the the largest object handle be larger
than the size ofzend_long
in 32-bit systems?
Only in the sense that it could theoretically wrap around to negative
numbers. Of course those would still serve as IDs just as well.
Example places where this would be useful:
I also recently wanted to track a large number of (cloneable)
small sets of objects in an application that sometimes used a lot of
memory,
and the fact that arrays support copy on write helped save memory
relative to SplObjectHash if arrays and integer keys were used.
See https://github.com/etsy/phan/pull/729#issuecomment-299289378
- Tyson Andre (tandre)
Hi!
No: In PHP 7 this is not possible, which is also why
spl_object_hash()
no
longer includes the handlers.
Ah, I missed that part.
--
Stas Malyshev
smalyshev@gmail.com
I'm unsure if an RFC is necessary. I have two pending questions.
Unless someone insists upon it, I'll put my release manager hat on and
say I'm fine with it just going in without an RFC.
-Sara