Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement spl_object_id(object $x) : int #2611

Closed
wants to merge 1 commit into from

Conversation

TysonAndre
Copy link
Contributor

@TysonAndre TysonAndre commented Jul 6, 2017

spl_object_id is a new function returning the object handle,
as a signed integer.

Discussion for this new function is ongoing on php-internals, see
https://marc.info/?t=143835274500003&r=1&w=2
(Subject: Exposing object handles to userland)

The object id is unique for the lifetime of the object.
When the object is garbage collected,
different objects may & will have the same object id.

  • This is also the case for the string generated by spl_object_hash

It is always possible to cast the object handle to a signed zend_long
in php 7.2. _zend_object->handle is always of the type uint32_t.
(zend_long is 32 bits on 32 bit builds, 64 bits on 64 bit builds)

As of php 7.0, the object id uniquely identifies the object,
there can't be two objects with the same id but different handlers
(See the implementation of spl_object_hash)

Skip the pointless XORing, as discussed in internals.

  • It was intended to avoid exposing in-memory addresses.
  • The object handle is not a memory address.
  • The output of var_dump() includes the object handle(id)

Commit a unit test of spl_object_id

Update NEWS

EDIT: rebased for 7.2.0beta1

@krakjoe krakjoe added the Feature label Jul 6, 2017

?>
===DONE===
<?php exit(0); ?>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not necessary and hides leaks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, removed. It's fairly common in ext/spl/tests, so I thought it was some sort of convention.

This was based on spl_object_hash.phpt, changing that is out of scope.

@nikic
Copy link
Member

nikic commented Jul 7, 2017

@sgolemon @remicollet Are you fine with landing this on 7.2 if no objections arise on the internals list in the next few days?

@nicolas-grekas
Copy link
Contributor

nicolas-grekas commented Jul 11, 2017

Polyfill implementation ready in symfony/polyfill-php72:
symfony/polyfill#97

spl_object_id is a new function returning the object handle,
as a signed integer.

Discussion for this new function is ongoing on php-internals, see
https://marc.info/?t=143835274500003&r=1&w=2

The object id is unique for the lifetime of the object.
When the object is garbage collected,
different objects may & will have the same object id.

- This is also the case for the string generated by spl_object_hash

It is always possible to cast the object handle to a **signed** zend_long
in php 7.2. _zend_object->handle is always of the type `uint32_t`.
(zend_long is 32 bits on 32 bit builds, 64 bits on 64 bit builds)

As of php 7.0, the object id uniquely identifies the object,
there can't be two objects with the same id but different handlers
(See the implementation of spl_object_hash)

Skip the pointless XORing, as discussed in internals.

- It was intended to avoid exposing in-memory addresses.
- The object handle is not a memory address.
- The output of var_dump() includes the object handle(id)

Commit a unit test of spl_object_id

Update NEWS
@TysonAndre
Copy link
Contributor Author

@nikic - This feature has been on the internals thread for a week without any objections, can it get merged? The feature freeze is on July 18th (3 days from now).

Sara Golemon responded on the internals thread earlier. https://marc.info/?l=php-internals&m=149977092723549&w=2

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

The build failure is a spurious timeout of the test suite as a whole on Travis CI.

@nicolas-grekas
Copy link
Contributor

friendly ping @sgolemon @remicollet

@TysonAndre TysonAndre changed the base branch from master to PHP-7.2 July 19, 2017 19:11
@TysonAndre TysonAndre changed the base branch from PHP-7.2 to master July 25, 2017 21:48
@nikic
Copy link
Member

nikic commented Aug 2, 2017

Merged as 5097e2e into PHP-7.2.

@nikic nikic closed this Aug 2, 2017
@Majkl578
Copy link
Contributor

Majkl578 commented Aug 2, 2017

Great to see this merged. 🎉 Although quite unfortunate to see this miss another beta window. :/

fabpot added a commit to symfony/polyfill that referenced this pull request Aug 11, 2017
This PR was merged into the 1.5-dev branch.

Discussion
----------

[7.2] Add polyfill for spl_object_id()

As [discussed on php-internals](https://externals.io/message/99751) and implemented in php/php-src#2611.
Implementation [borrowed from VarDumper](https://github.com/symfony/symfony/blob/2.7/src/Symfony/Component/VarDumper/Cloner/VarCloner.php#L300).

Commits
-------

06995f5 [7.2] Add polyfill for spl_object_id()
TysonAndre added a commit to TysonAndre/php-src that referenced this pull request Nov 5, 2017
php-pulls pushed a commit that referenced this pull request Nov 6, 2017
@TysonAndre TysonAndre deleted the spl_object_id branch May 7, 2020 23:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants