Skip to content

Initial ReflectionReference implementation #3550

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

Closed
wants to merge 1 commit into from

Conversation

nikic
Copy link
Member

@nikic nikic commented Sep 25, 2018

Implementation of ReflectionReference based on the discussion in https://externals.io/message/102638. Currently the class definition is

final class ReflectionReference {
    /* Returns ReflectionReference if array element is a reference, null otherwise. */
    public static function fromArrayElement(array $array, int|string $key): ?ReflectionReference;
    /* Returns unique identifier for the reference. The return value format is unspecified. */
    public function getId(): int|string;

    private function __construct(); // Always throws
    private function __clone(); // Always throws
}

The return value of getId() uniquely identifies the reference for the duration of its lifetime. An ID may be reused if the reference is destroyed. The format of the return value is unspecified any may change. Only the fact that it will be an integer or string is guaranteed.

In the current implementation the address of the reference is directly returned as the ID. We should be hiding the address here, possibly by hashing it with a secret key. the ID is a raw SHA1 hash of the reference address and a per-process key. Raw meaning 20 character binary data, no hex encoding.

@nikic
Copy link
Member Author

nikic commented Sep 25, 2018

/cc @nicolas-grekas

@nicolas-grekas
Copy link
Contributor

Thanks, I'll definitely check this PR!

@nikic
Copy link
Member Author

nikic commented Sep 26, 2018

@sarciszewski Any tips on how to return scrambled memory addresses, for the getId() function? I could run the address through sha1 together with a per-process secret key, but I'd prefer something more lightweight. A fast 64-bit cipher would probably be ideal here.

@php-pulls
Copy link

Comment on behalf of petk at php.net:

Labelling

@nikic nikic force-pushed the reflection-reference branch 2 times, most recently from f3ea6ef to d96bef5 Compare January 15, 2019 10:38
@nikic nikic added RFC and removed Feature labels Jan 15, 2019
@nicolas-grekas
Copy link
Contributor

Should the class implements Reflector for consistency with other reflection-related classes?
Should it throw on serialize?
(maybe that's already the case btw, in which case sorry for asking)

@nikic
Copy link
Member Author

nikic commented Feb 6, 2019

Should the class implements Reflector for consistency with other reflection-related classes?

Not if we can avoid it :) Reflector is quite the abomination and should really be removed entirely... I'd prefer not to have implicit stringification on this class just to satisfy this interface. Thankfully there is precedent in not implementing Reflector in the form of ReflectionGenerator.

Should it throw on serialize?

Yes it should! I've made serialize throw for all other reflection classes a while ago, but forgot it here...

@nikic nikic force-pushed the reflection-reference branch from cbead86 to d712326 Compare February 7, 2019 14:58
@nikic
Copy link
Member Author

nikic commented Feb 7, 2019

Serialization is now properly forbidden.

@nikic
Copy link
Member Author

nikic commented Feb 13, 2019

RFC accepted, merged as 6347f0b.

@nikic nikic closed this Feb 13, 2019
jrfnl added a commit to PHPCompatibility/PHPCompatibility that referenced this pull request Jun 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants