rfc:fallback-to-root-scope-deprecation
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
rfc:fallback-to-root-scope-deprecation [2018/02/03 07:48] – wesnetmo | rfc:fallback-to-root-scope-deprecation [2018/02/03 12:30] – wesnetmo | ||
---|---|---|---|
Line 9: | Line 9: | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | Fallback to global scope allow users to access | + | Fallback to global scope allows namespaces |
- | At the time the feature was introduced, there was no `use function|const foo` syntax available | + | <code php> |
- | today, authors that really hate writing `\strlen()` can do instead `use function {strlen, substr}` on top of their files. | + | namespace Bar; |
+ | strlen(); | ||
+ | // first tries to call \Bar\strlen() | ||
+ | // if not found, fallbacks to \strlen() | ||
+ | </ | ||
This feature causes more harm than good, since it prevents PHP from implementing **in a sensible manner** long-requested features like function autoloading. Additionally, | This feature causes more harm than good, since it prevents PHP from implementing **in a sensible manner** long-requested features like function autoloading. Additionally, | ||
Line 18: | Line 22: | ||
===== Proposal ===== | ===== Proposal ===== | ||
- | This RFC proposes to deprecate the fallback to root scope, by emitting a '' | + | This RFC proposes to deprecate the fallback to root scope, by emitting a deprecation notice, e.g.: |
< | < | ||
Line 25: | Line 29: | ||
</ | </ | ||
- | It also proposes, considered the entity of the change, that the " | + | It also proposes, considered the entity of the change, that the " |
In fact, if the feature is removed and autoloading of functions and constants is introduced at the same time, authors that failed to update their code can easily shim it using just few lines of code: | In fact, if the feature is removed and autoloading of functions and constants is introduced at the same time, authors that failed to update their code can easily shim it using just few lines of code: | ||
Line 67: | Line 71: | ||
); | ); | ||
</ | </ | ||
+ | |||
+ | However, if this RFC passes, authors should try to avoid the Notice by writing `\strlen()` or `use function {strlen, strpos};` in their code, which are **plenty of solutions covering any code style**. | ||
+ | |||
+ | ===== Migration Tools ===== | ||
+ | |||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * More coming soon... | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
Line 82: | Line 95: | ||
===== References ===== | ===== References ===== | ||
- | @TODO link discussion | + | - [[https:// |
rfc/fallback-to-root-scope-deprecation.txt · Last modified: 2018/02/03 16:26 by wesnetmo