Table of Contents

RFC: Merge Symbol Tables

Introduction

Currently we have symbol tables separate from each other based on kind. For instance, constants, functions, and classes/interfaces/traits all have their own tables. This allows us to use the same name for a constant, function, and a class all simultaneously:

const Symbol = 'symbol';
function symbol() {}
class Symbol {}
// no errors

This behavior is sometimes useful but prohibits other, more useful features such as the ability to use a function name as a callback without using strings:

// this looks for constant strlen, not function strlen:
array_map(strlen, ['hello', 'world']);
 
// must use the string:
array_map('strlen', ['hello', 'world']);

This makes it difficult to rename functions because it is more difficult to determine if a string is meant to be the function name or not compared to a symbolic usage. This RFC proposes to unify the constant, function, and class/interface/trait symbol tables into one.

Proposal

This RFC proposes to unify the constant, function, and class/interface/trait symbol tables into one.

Benefits

TODO

Backward Incompatible Changes

Any projects currently using the same name for different kinds of symbols will now get a redefinition error.

Proposed PHP Version(s)

This RFC targets PHP 8.0 or PHP 9.0 because of the backwards compatibility breaks.

RFC Impact

To Existing Extensions

TODO

To Opcache

Depending on the exact implementation it may be possible for opcache to work without any changes.

Open Issues

Constants are currently case sensitive while functions and classes are case insensitive. Should we unify the case sensitivity at the same time?

Future Scope

This sections details areas where the feature might be improved in future, but that are not currently proposed in this RFC.

Proposed Voting Choices

This RFC requires two-thirds of the votes to be in favor of logically unifying the symbol tables.

Patches and Tests

At this stage there is no patch.

References

Links to external references, discussions or RFCs