On Wed, Jul 5, 2017 at 2:01 AM, tyson andre <tysonandre...@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.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. > 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: > - https://marc.info/?t=143835274500003&r=1&w=2 > > Previous comment by a PHP maintainer in support of `spl_object_id()` > - https://marc.info/?l=php-internals&m=143837339210596&w=2 > > 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 of `zend_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: > > 1. https://marc.info/?l=php-internals&m=143849841618494&w=2 > > 2. 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) > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >