So far this proposal only discusses reflections of PHP declarations / symbols.
What would we do for e.g. ReflectionObject? Return the spl_object_hash()? Or return the hash of the instantiated class? Or a hash of the serialized object? We need to return something, because ReflectionObject extends ReflectionClass. On 11 December 2017 at 03:11, Andreas Hennings <andr...@dqxtech.net> wrote: > I propose to add a new method ::getHash() to reflection API classes. > > Such that: > > Two reflectors return the same hash, if and only if: > > 1. the reflected items have the same type (class, method, parameter etc), AND. > 2. the reflected items have the same names, AND. > 3. the reflected items have the same PHP code (e.g. for distinct > processes), AND. > 4. optionally: Every base class, every implemented interface and every > used trait has the same PHP code (and thus, the same hash). > 5. optionally: The PHP version and PHP settings are the same. (*) > > Such an id can be used as a cache key between requests. > > It would automatically change / become invalid, if: > - new code changes are deployed, OR. > - different processes include different files that each declare the > same class, OR. > - php is upgraded, or php settings change. (*) > > Currently the best way (for practicality and performance) to achieve > something like this is to get the timestamp of the file that defines > the class. > > Note: The behavior of a function can change if the code of another > function that is being called is modified. > The hash would still be the same, because it does not look at > functions being called. > > (*) Maybe for the php version and settings there should instead be a > global hash, which can be used as salt for a combined cache key. > > > I was first going to propose to add this new method directly on > \Reflector interface. > But this would be a BC break, because userland classes that implement > this interface would break. > > So instead, either > - add it to each class separately, or > - add a new interface \Reflector2 extends \Reflector (yeah, versioned > interfaces!), and let all reflection classes implement that. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php